void ledSetProfile(LedType_t type,bool connected) { switch(type) { case LedTypeA2DP: PioSetDir(LED_A2DP,LED_A2DP); if(connected) PioSet(LED_A2DP,0); else PioSet(LED_A2DP,LED_A2DP); break; case LedTypeHFP: PioSetDir(LED_HSP,LED_HSP); if(connected) PioSet(LED_HSP,0); else PioSet(LED_HSP,LED_HSP); break; case LedTypePBAP: case LedTypeSCO: PioSetDir(LED_SPP,LED_SPP); if(connected) PioSet(LED_SPP,0); else PioSet(LED_SPP,LED_SPP); break; default: break; } }
extern void WeightInitHardware(void) { /* Set up PIOs * PIO11 - Button */ /* Set the button PIO to user mode */ PioSetModes(BUTTON_PIO_MASK, pio_mode_user); /* Set the PIO direction as input. */ PioSetDir(BUTTON_PIO, PIO_DIRECTION_INPUT); /* Pull up the PIO. */ PioSetPullModes(BUTTON_PIO_MASK, pio_mode_strong_pull_up); /* Initialise Buzzer Hardware */ BuzzerInitHardware(); /* Set up button on PIO11 */ PioSetEventMask(BUTTON_PIO_MASK, pio_event_mode_both); /* Save power by changing the I2C pull mode to pull down */ PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_down); #ifdef ENABLE_LEDBLINK /* PIO 4 is being used for LED glowing. */ PioSetModes(PIO_BIT_MASK(LED_PIO), pio_mode_user); /* user mode set */ PioSetDir(LED_PIO, PIO_DIRECTION_OUTPUT); /* output */ PioSet(LED_PIO, FALSE); /* set low */ #endif /* ENABLE_LEDBLINK */ }
void AppInit(sleep_state last_sleep_state) { /* set all PIOs to inputs and pull them down */ PioSetModes(0xFFFFFFFFUL, pio_mode_user); PioSetDirs(0xFFFFFFFFUL, FALSE); PioSetPullModes(0xFFFFFFFFUL, pio_mode_strong_pull_down); /* Set LED0 and LED1 to be controlled directly via PioSet */ PioSetModes((1UL << PIO_LED0), pio_mode_user); /* Configure LED0 and LED1 to be outputs */ PioSetDir(PIO_LED0, PIO_DIR_OUTPUT); /* Set the LED0 and LED1 to have strong internal pull ups */ PioSetPullModes((1UL << PIO_LED0), pio_mode_strong_pull_up); /* Configure button to be controlled directly */ PioSetMode(PIR_SIGNAL, pio_mode_user); /* Configure button to be input */ PioSetDir(PIR_SIGNAL, PIO_DIR_INPUT); /* Set weak pull up on button PIO, in order not to draw too much current * while button is pressed */ PioSetPullModes((1UL << PIR_SIGNAL), pio_mode_weak_pull_down); /* Set the button to generate sys_event_pio_changed when pressed as well * as released */ PioSetEventMask((1UL << PIR_SIGNAL), pio_event_mode_rising); /* disable wake up on UART RX */ SleepWakeOnUartRX(FALSE); /* pull down the I2C lines */ PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_down); /* Reset LED sequence */ restartLedSeq(); SleepModeChange(sleep_mode_deep); TimerInit(MAX_APP_TIMERS, (void*)app_timers); BeaconInit(); pirStatusServiceInit(); }
/*----------------------------------------------------------------------------* * NAME * InitHardware * * DESCRIPTION * This function is called to initialise the application hardware. * * PARAMETERS * None * * RETURNS * Nothing *----------------------------------------------------------------------------*/ extern void InitHardware(void) { /* Setup PIOs * PIO11 - Button */ /* Set the button PIO to user mode */ PioSetModes(BUTTON_PIO_MASK, pio_mode_user); /* Set the PIO direction as input */ PioSetDir(BUTTON_PIO, PIO_DIRECTION_INPUT); /* Pull up the PIO */ PioSetPullModes(BUTTON_PIO_MASK, pio_mode_strong_pull_up); /* Initialise buzzer hardware */ BuzzerInitHardware(); /* Initialise LED hardware */ LedInitHardware(); /* Request an event when the button PIO changes state */ PioSetEventMask(BUTTON_PIO_MASK, pio_event_mode_both); /* Save power by changing the I2C pull mode to pull down.*/ PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_down); }
static void disableLDO(void) { /** set input, don't know pull-up detail, need to clarify **/ PioSetDir(PIO_LDO_ENABLE, 0); /** maybe this could change, according the pio.h document, all pios has weak pull-up / pull-down, according the bit value in corresponding output register **/ PioSet(PIO_LDO_ENABLE, 0); }
void LcdDisplayInitRst(void) { /* Set up the PIOs for the RST pin on the LCD display. */ PioSetPullModes((1UL << PIO_RST), pio_mode_no_pulls); PioSetMode(PIO_RST, pio_mode_user); PioSetDir(PIO_RST, TRUE); /* Output */ PioSet(PIO_RST, TRUE); } /* LcdDisplayInitRst */
static void trigger_pull_up(void) { /** set as input **/ PioSetDir(SCANNER_TRIGGER_MASK, 0); /** weak pull-up according to pio.h document **/ PioSet(SCANNER_TRIGGER_MASK, SCANNER_TRIGGER_MASK); }
static void trigger_drive_low(void) { /** set output **/ PioSetDir(SCANNER_TRIGGER_MASK, SCANNER_TRIGGER_MASK); /** drive low **/ PioSet(SCANNER_TRIGGER_MASK, 0); }
void InitPioTask() { /* Set up task 1 handler */ pioApp.task.handler = PioTaskHandler; pioApp.new_heater_state = Heater0; MessagePioTask(&pioApp.task); PioSetDir(0x03, 0x03); PioSet(0x03, 0); MessageSend( &pioApp.task, NewHeaterState, 0); }
void LcdDisplayInitPwm(void) { PioSetMode(PIO_LED, pio_mode_user); PioSetDir(PIO_LED, TRUE); /* Output */ PioSet(PIO_LED, FALSE); PioSetMode(PIO_LED, pio_mode_pwm0); /* PIO is controlled by PWM. */ LcdDisplayBacklight(10, 10); /* Start with dim light. */ PioEnablePWM(PWM_ID_LED, TRUE); } /* LcdDisplayInitPwm */
/*----------------------------------------------------------------------------* * NAME * InitAlertTagHardware - initialize application hardware * * DESCRIPTION * This function is called upon a power reset to initialize the PIOs * and configure their initial states. * * RETURNS * Nothing. * *----------------------------------------------------------------------------*/ extern void InitAlertTagHardware(void) { #ifndef DEBUG_THRU_UART /* Don't wakeup on UART RX line */ SleepWakeOnUartRX(FALSE); #endif /* Setup PIOs * PIO3 - Buzzer - BUZZER_PIO * PIO4 - LED 1 - LED_PIO * PIO11 - Button - BUTTON_PIO */ PioSetModes(PIO_BIT_MASK(BUTTON_PIO), pio_mode_user); PioSetDir(BUTTON_PIO, PIO_DIRECTION_INPUT); /* input */ PioSetPullModes(PIO_BIT_MASK(BUTTON_PIO), pio_mode_strong_pull_up); /* Setup button on PIO11 */ PioSetEventMask(PIO_BIT_MASK(BUTTON_PIO), pio_event_mode_both); #ifdef ENABLE_LEDBLINK /* PWM is being used for LED glowing.*/ PioSetModes(PIO_BIT_MASK(LED_PIO), pio_mode_pwm1); /* Advertising parameters are being configured for PWM right now. When * application moves to connection state, we change PWM parameters to * the ones for connection */ PioConfigPWM(LED_PWM_INDEX_1, pio_pwm_mode_push_pull, DULL_LED_ON_TIME_ADV, DULL_LED_OFF_TIME_ADV, DULL_LED_HOLD_TIME_ADV, BRIGHT_LED_OFF_TIME_ADV, BRIGHT_LED_ON_TIME_ADV, BRIGHT_LED_HOLD_TIME_ADV, LED_RAMP_RATE); PioEnablePWM(LED_PWM_INDEX_1, FALSE); #endif /* ENABLE_LEDBLINK */ #ifdef ENABLE_BUZZER PioSetModes(PIO_BIT_MASK(BUZZER_PIO), pio_mode_pwm0); /* Configure the buzzer on PIO3 */ PioConfigPWM(BUZZER_PWM_INDEX_0, pio_pwm_mode_push_pull, DULL_BUZZ_ON_TIME, DULL_BUZZ_OFF_TIME, DULL_BUZZ_HOLD_TIME, BRIGHT_BUZZ_ON_TIME, BRIGHT_BUZZ_OFF_TIME, BRIGHT_BUZZ_HOLD_TIME, BUZZ_RAMP_RATE); PioEnablePWM(BUZZER_PWM_INDEX_0, FALSE); #endif /* ENABLE_BUZZER */ /* Set the I2C pins to pull down */ PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_down); }
/*----------------------------------------------------------------------------* * NAME * InitTimeClientHardware-initialize application hardware * * DESCRIPTION * This function is called upon a power reset to initialize the PIOs * and configure their initial states. * * RETURNS * Nothing. * *----------------------------------------------------------------------------*/ extern void InitTimeClientHardware(void) { /* Setup PIOs * PIO3 - Buzzer - BUZZER_PIO * PIO4 - LED 1 - LED_PIO * PIO11 - Button - BUTTON_PIO */ PioSetModes(PIO_BIT_MASK(BUTTON_PIO), pio_mode_user); PioSetDir(BUTTON_PIO, PIO_DIRECTION_INPUT); /* input */ PioSetPullModes(PIO_BIT_MASK(BUTTON_PIO), pio_mode_strong_pull_up); /* Setup button on PIO11 */ PioSetEventMask(PIO_BIT_MASK(BUTTON_PIO), pio_event_mode_both); /* Initialize Buzzer Hardware */ BuzzerInitHardware(); #ifdef ENABLE_LEDBLINK /* PWM is being used for LED glowing.*/ PioSetModes(PIO_BIT_MASK(LED_PIO), pio_mode_pwm1); /* Advertising parameters are being configured for PWM right now. When * application moves to connection state, we change PWM parameters to * the ones for connection */ PioConfigPWM(LED_PWM_INDEX_1, pio_pwm_mode_push_pull, DULL_LED_ON_TIME_ADV, DULL_LED_OFF_TIME_ADV, DULL_LED_HOLD_TIME_ADV, BRIGHT_LED_OFF_TIME_ADV, BRIGHT_LED_ON_TIME_ADV, BRIGHT_LED_HOLD_TIME_ADV, LED_RAMP_RATE); PioEnablePWM(LED_PWM_INDEX_1, FALSE); #endif /* ENABLE_LEDBLINK */ /* Set the I2C pins to pull down */ PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_down); }
static void enableLDO(void) { /** set output and drive high **/ PioSetDir(PIO_LDO_ENABLE, PIO_LDO_ENABLE); PioSet(PIO_LDO_ENABLE, PIO_LDO_ENABLE); }
/*----------------------------------------------------------------------------* * NAME * AppInit * * DESCRIPTION * This user application function is called after a power-on reset * (including after a firmware panic), after a wakeup from Hibernate or * Dormant sleep states, or after an HCI Reset has been requested. * * NOTE: In the case of a power-on reset, this function is called * after AppPowerOnReset(). * * PARAMETERS * last_sleep_state [in] Last sleep state * * RETURNS * Nothing *----------------------------------------------------------------------------*/ void AppInit(sleep_state last_sleep_state) { /* Initialise UART communications */ DebugInit(1, NULL, NULL); DebugWriteString("Configuring PWM Modes\r\n"); /* Configure the output PIO on which the slow flashing LED signal is * generated */ PioSetDir(PIO_LED, PIO_DIR_OUTPUT); /* SLOW FLASHING WITH PWM: * Configure PWM 0 to have the following characteristics * DULL LED Light is generated by having pulses of 0ms ON and * 6ms OFF (~0% duty cycle) * BRIGHT LED Light is generated by having pulses of 6ms ON and * 0ms OFF (~100% duty cycle) * Dullest and Brightest level are held for ~1s * * The brightness level ramps for ~1s when going from dullest to * brightest and vice-versa */ if (PioConfigPWM(0, pio_pwm_mode_push_pull, /* Pulse timings for the dullest part of the sequence: * dullest part of the sequence has the pulse off for the whole * period, in effect the line stays low for the duration for which * the dullest part of the sequence lasts. */ 0, /* ON time for the pulse is 0us */ 255, /* OFF time for the pulse is (255 * 30)us */ 62, /* Dullest part of the sequence lasts for ( 62 * 16 )ms before ramping up to the brightest part of the sequence */ /* Pulse timings for the brightest part of the sequence: * brightest part of the sequence has the pulse ON for the whole * period, in effect the line stays high for the duration for which * the brightest part of the sequence lasts. */ 255, /* ON time for the pulse is (255 * 30)us */ 0, /* OFF time for the pulse is 0us */ 62, /* Brightest part of the sequence lasts for ( 62 * 16 )ms before ramping down to the dullest part of the sequence */ /* Ramping between dullest and brightest parts of the sequence * This parameter determines the duration for which the ramping * lasts when going from dullest to the brightest (and vice-versa). * * The total duration for which the ramping lasts is determined by * multiplying this value with one less than the difference between * the on_time or off_time of the two states, whichever is bigger; * in the units of 30us * */ 132 /* Ramping lasts for ((255-1) * 132 * 30)us */ )) { DebugWriteString("PWM0 was set to ramp between brightest and dullest " "levels\r\n"); /* Connect PWM0 output to LED */ PioSetMode(PIO_LED, pio_mode_pwm0); /* Enable the PWM0 */ PioEnablePWM(0, TRUE); } else { DebugWriteString("PWM0 couldn't be configured\r\n"); } /* Set both outputs to have strong internal pull ups */ PioSetPullModes((1UL << PIO_MOTOR) | (1UL << PIO_LED), pio_mode_strong_pull_up); /* Configure motor PIO to be output */ PioSetDir(PIO_MOTOR, PIO_DIR_OUTPUT); /* Connect PWM1 output to motor PIO */ PioSetMode(PIO_MOTOR, pio_mode_pwm1); /* Initialise timers */ TimerInit(MAX_APP_TIMERS, app_timers); /* Call the function (with a dummy timer ID to start with) to configure * the PWM1 with initial duty cycle and start a timer. When the timer * expires the same function gets called again and the duty cycle for * PWM1 gets updated. It takes care of restarting the timer and ensuring * that duty cycle alternates between 0% and 100% back and forth. */ dutyCycleTask(TIMER_INVALID); /* Enable the PWM1 */ PioEnablePWM(1, TRUE); }
static void disable_scanner(void) { /** drive low **/ PioSetDir(SCANNER_POWER_MASK, SCANNER_POWER_MASK); PioSet(SCANNER_POWER_MASK, 0); }
static void enable_scanner(void) { /** drive high **/ PioSetDir(SCANNER_POWER_MASK, SCANNER_POWER_MASK); PioSet(SCANNER_POWER_MASK, SCANNER_POWER_MASK); }