static void ledConnTimerExpiry(timer_id id) { if(g_weight_hw_data.led_off_conn_tid == id) { /* The application starts LED on timer for LED_ON_CONN_PERIOD after the * expiry of LED off timer in connected state. */ TimerDelete(g_weight_hw_data.led_off_conn_tid); g_weight_hw_data.led_off_conn_tid=TIMER_INVALID; PioSet(LED_PIO, TRUE); g_weight_hw_data.led_on_conn_tid = TimerCreate(LED_ON_CONN_PERIOD,TRUE, ledConnTimerExpiry); } else if(g_weight_hw_data.led_on_conn_tid == id) { /* The application starts LED off timer for LED_OFF_CONN_PERIOD after * the expiry of LED on timer in connected state. */ TimerDelete(g_weight_hw_data.led_on_conn_tid); g_weight_hw_data.led_on_conn_tid=TIMER_INVALID; PioSet(LED_PIO,FALSE); g_weight_hw_data.led_off_conn_tid = TimerCreate(LED_OFF_CONN_PERIOD, TRUE, ledConnTimerExpiry); } }
static void ledAdTimerExpiry(timer_id id) { if(g_weight_hw_data.led_off_ad_tid == id) { /* The application starts LED on timer for LED_ON_AD_PERIOD after the * expiry of LED off timer in advertising state. */ TimerDelete(g_weight_hw_data.led_off_ad_tid); g_weight_hw_data.led_off_ad_tid=TIMER_INVALID; PioSet(LED_PIO, TRUE); g_weight_hw_data.led_on_ad_tid = TimerCreate(LED_ON_AD_PERIOD,TRUE, ledAdTimerExpiry); } else if(g_weight_hw_data.led_on_ad_tid == id) { /* The application starts LED off timer for LED_OFF_AD_PERIOD after the * expiry of LED on timer in advertising state. */ TimerDelete(g_weight_hw_data.led_on_ad_tid); g_weight_hw_data.led_on_ad_tid=TIMER_INVALID; PioSet(LED_PIO,FALSE); g_weight_hw_data.led_off_ad_tid = TimerCreate(LED_OFF_AD_PERIOD,TRUE, ledAdTimerExpiry); } }
static void goToNextLedSeq(uint32 onOff) { if(onOff == 0) { PioSet(PIO_LED0, 0); } else { PioSet(PIO_LED0, 1); } }
void LcdDisplayInit(uint8 i2c_address) { /* Reset the display in case it is in unknown state. */ PioSet(PIO_RST, FALSE); TimeDelayUSec(MILLISECOND); PioSet(PIO_RST, TRUE); TimeDelayUSec(MILLISECOND); /* Change these codes depending on the LCD display being used. */ /* Clear (or Home) must be the last command. */ uint8 lcd_init[] = {0x00, 0x39, 0x14, 0x74, 0x54, 0x6F, 0x38, 0x0C, 0x06, 0x01}; LcdDisplayI2cWrite(i2c_address, lcd_init, sizeof(lcd_init)/sizeof(lcd_init[0])); TimeDelayUSec(1000); /* Need long delay after Clear and Home. */ } /* LcdDisplayInit */
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 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 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); }
/*----------------------------------------------------------------------------* * NAME * SetIndication * * DESCRIPTION * This function indicates the app state through LED blinking * * RETURNS/MODIFIES * Nothing. * *----------------------------------------------------------------------------*/ extern void SetIndication(app_indication state) { #ifdef ENABLE_LEDBLINK if(state == app_ind_stop) { /*Stop LED glowing */ PioEnablePWM(LED_PWM_INDEX_1, FALSE); /* Reconfigure LED to pio_mode_user. This reconfiguration has been done * because When PWM is disabled, LED pio value remains same as it was at * the exact time of disabling. So if LED was on, it may remain ON even * after PWM disabling. So it is better to reconfigure it to user mode. * It will reconfigured to PWM mode while enabling. */ PioSetModes(PIO_BIT_MASK(LED_PIO), pio_mode_user); PioSet(LED_PIO, FALSE); } else { if(state == app_ind_adv) { /* Fast Blinking for advertising */ 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_ON_TIME_ADV, BRIGHT_LED_OFF_TIME_ADV, BRIGHT_LED_HOLD_TIME_ADV, LED_RAMP_RATE); } else if(state == app_ind_conn) { /* slow blinking for connected state */ PioConfigPWM(LED_PWM_INDEX_1, pio_pwm_mode_push_pull, DULL_LED_ON_TIME_CONN, DULL_LED_OFF_TIME_CONN, DULL_LED_HOLD_TIME_CONN, BRIGHT_LED_ON_TIME_CONN, BRIGHT_LED_OFF_TIME_CONN, BRIGHT_LED_HOLD_TIME_CONN, LED_RAMP_RATE); } PioSetModes(PIO_BIT_MASK(LED_PIO), pio_mode_pwm1); /*Start LED glowing */ PioEnablePWM(LED_PWM_INDEX_1, TRUE); PioSet(LED_PIO, TRUE); } #endif /* ENABLE_LEDBLINK */ }
static void trigger_drive_low(void) { /** set output **/ PioSetDir(SCANNER_TRIGGER_MASK, SCANNER_TRIGGER_MASK); /** drive low **/ PioSet(SCANNER_TRIGGER_MASK, 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 */
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 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 SetIndication(app_indication state) { #ifdef ENABLE_LEDBLINK if(state == stop_ind) { /* Stop LED glowing */ PioSet(LED_PIO, FALSE); /* Delete LED timers */ TimerDelete(g_weight_hw_data.led_on_ad_tid); g_weight_hw_data.led_on_ad_tid = TIMER_INVALID; TimerDelete(g_weight_hw_data.led_off_ad_tid); g_weight_hw_data.led_off_ad_tid = TIMER_INVALID; TimerDelete(g_weight_hw_data.led_on_conn_tid); g_weight_hw_data.led_on_conn_tid = TIMER_INVALID; TimerDelete(g_weight_hw_data.led_off_conn_tid); g_weight_hw_data.led_off_conn_tid = TIMER_INVALID; } else { if(state == advertising_ind) { /* Create a timer for LED_ON_AD_PERIOD for advertising state */ PioSet(LED_PIO, TRUE); g_weight_hw_data.led_on_ad_tid = TimerCreate(LED_ON_AD_PERIOD,TRUE, ledAdTimerExpiry); } else if(state == connected_ind) { /* Create a timer for LED_ON_CONN_PERIOD for connected state */ PioSet(LED_PIO, TRUE); g_weight_hw_data.led_on_conn_tid = TimerCreate(LED_ON_CONN_PERIOD, TRUE, ledConnTimerExpiry); } } #endif /* ENABLE_LEDBLINK */ }
static void enable_scanner(void) { /** drive high **/ PioSetDir(SCANNER_POWER_MASK, SCANNER_POWER_MASK); PioSet(SCANNER_POWER_MASK, SCANNER_POWER_MASK); }
static void disable_scanner(void) { /** drive low **/ PioSetDir(SCANNER_POWER_MASK, SCANNER_POWER_MASK); PioSet(SCANNER_POWER_MASK, 0); }
static void enableLDO(void) { /** set output and drive high **/ PioSetDir(PIO_LDO_ENABLE, PIO_LDO_ENABLE); PioSet(PIO_LDO_ENABLE, PIO_LDO_ENABLE); }