Exemple #1
0
int app_batt_alert_timer_handler(ke_msg_id_t const msgid,
                                        void const *param,
										ke_task_id_t const dest_id,
										ke_task_id_t const src_id)
{
		
	
		//Read LED GPIO state
    if(bat_lvl_alert_used)
    {		
		if (bat_led_state)
		{
            GPIO_SetInactive( bat_led_port, bat_led_pin);            	

			bat_led_state = 0;
			app_timer_set(APP_BATT_ALERT_TIMER, dest_id, 20);
#ifdef CUSTOM_BATTERY_LEVEL_MEASUREMENTS___BOOST_MODE_CONFIGURATION
            if (app_get_sleep_mode())
                app_force_active_mode();    // prevent sleep only if enabled
#endif //CUSTOM_BATTERY_LEVEL_MEASUREMENTS___BOOST_MODE_CONFIGURATION
		}
		else
		{
            GPIO_SetActive( bat_led_port, bat_led_pin);

			bat_led_state = 1;
			app_timer_set(APP_BATT_ALERT_TIMER, dest_id, 5);
#ifdef CUSTOM_BATTERY_LEVEL_MEASUREMENTS___BOOST_MODE_CONFIGURATION
            app_restore_sleep_mode(); 
#endif //CUSTOM_BATTERY_LEVEL_MEASUREMENTS___BOOST_MODE_CONFIGURATION
		}
    }
		
    return (KE_MSG_CONSUMED);
}
Exemple #2
0
/**
 ****************************************************************************************
 * @brief Read from 3-wire SPI
 * @param[in] registerIndex: Target address (A6..A0)
 *
 * @return  byte read
 ****************************************************************************************
 */
uint8_t read_from_3wire_SPI_register(uint8_t registerIndex, uint8_t is_last_transaction)
{
    static uint8_t i, dataRead;

    GPIO_SetInactive(cs.port, cs.pin);                              // pull CS low

    GPIO_SetPinFunction( sdio.port, sdio.pin, OUTPUT, PID_SPI_DO);  // configure SDIO as output

    SetWord16(SPI_RX_TX_REG0, (uint16_t)(registerIndex) );          // MSB set to HIGH - A6..A0 Address of register to write to
    do {
    } while (GetBits16(SPI_CTRL_REG,SPI_INT_BIT)==0);               // polling to wait for spi transmission

    SetWord16(SPI_CLEAR_INT_REG, 0);                                //Clear SPI_CTRL_REG[SPI_INT_BIT] interrupt

    GPIO_SetPinFunction( sdio.port, sdio.pin, INPUT, PID_SPI_DI);   // configure SDIO as input

    for (i=0; i<TsradCounter; i++);                                 // {DEV.NOTE#: For Mouse sensor Delay > Tsrad = 4us <-- suitable counter is 6}

    SetWord16(SPI_RX_TX_REG0, (uint16_t)0x00 );                     // dummy write data - read data
    do {
    } while (GetBits16(SPI_CTRL_REG,SPI_INT_BIT)==0);               // polling to wait for spi transmission

    SetWord16(SPI_CLEAR_INT_REG, 0);                                //Clear SPI_CTRL_REG[SPI_INT_BIT] interrupt

    dataRead = GetWord16(SPI_RX_TX_REG0);                           // read received byte

    SetWord16(SPI_CLEAR_INT_REG, 0x01);                             // clear pending flag

    if(is_last_transaction)
        GPIO_SetActive(cs.port, cs.pin);                              // set CS high

    return dataRead;
}
Exemple #3
0
int app_batt_alert_timer_handler(ke_msg_id_t const msgid,
                                        void const *param,
										ke_task_id_t const dest_id,
										ke_task_id_t const src_id)
{
		
	
		//Read LED GPIO state
    if(bat_lvl_alert_used)
    {		
#if 0
			if (bat_led_state)
			{
				if(GPIO_GetPinStatus(GPIO_ALERT_PWR_PORT,GPIO_ALERT_PWR_PIN)==false)
				{
					//正在充电
				}
				else
				{
					GPIO_SetActive( bat_led_port, bat_led_pin);  //V3.2版本后将黄灯逻辑电平反向
					bat_led_state = 0;
				}
				app_timer_set(APP_BATT_ALERT_TIMER, dest_id, 50);//20,电池电量低,报警灯闪烁速度,,delay延时
			}
			else
			{
				GPIO_SetInactive( bat_led_port, bat_led_pin);//V3.2版本后将黄灯逻辑电平反向
				bat_led_state = 1;
				app_timer_set(APP_BATT_ALERT_TIMER, dest_id, 50);//5,电池电量低,报警灯闪烁速度,delay延时
			}
#endif
    }
		
    return (KE_MSG_CONSUMED);
}
void uart_write_ext_wkup_func(uint8_t *bufptr, uint32_t size, void (*callback) (uint8_t))
{
    // Sanity check
    ASSERT_ERR(bufptr != NULL);
    ASSERT_ERR(size != 0);
    ASSERT_ERR(uart_env.tx.bufptr == NULL);
	
		GPIO_SetActive (EXT_WAKEUP_PORT, EXT_WAKEUP_PIN);
			
    // Prepare TX parameters
    uart_env.tx.size = size;
    uart_env.tx.bufptr = bufptr;
		uart_env.tx.callback = callback;

    /* start data transaction
     * first isr execution is done without interrupt generation to reduce
     * interrupt load
     */
    uart_thr_empty_isr();
    if (uart_env.tx.bufptr != NULL)
    {
			uart_thr_empty_setf(1);
    }
		GPIO_SetInactive (EXT_WAKEUP_PORT, EXT_WAKEUP_PIN);
}
/**
 ****************************************************************************************
 * @brief Sets the Red LED to blink
 *
 * @param   None    
 *
 * @return  void
 ****************************************************************************************
 */
void red_led_blink()
{
    if (LED_STATE_OFF) {
        GPIO_SetInactive(KBD_RED_LED_PORT,      KBD_RED_LED_PIN);       // red: low - on
    } else {
        GPIO_SetActive  (KBD_RED_LED_PORT,      KBD_RED_LED_PIN);       // red: high - on
    }
}
Exemple #6
0
/**
 ****************************************************************************************
 * @brief Deactivate communication with the 3-wire SPI
 ****************************************************************************************
 */
void deactivate_3wire_spi(void)
{
    GPIO_SetActive(cs.port, cs.pin);                                            // leave CS high
    GPIO_SetPinFunction( sdio.port, sdio.pin, INPUT, PID_SPI_DI);
    NVIC_DisableIRQ(SPI_IRQn);                                                  // disable SPI interrupt
    SetBits16(SPI_CTRL_REG, SPI_ON, 0);                                         // close SPI block, if opened
    SetBits16(CLK_PER_REG, SPI_ENABLE, 0);                                      // disable clock for SPI
}
/**
 ****************************************************************************************
 * @brief Sets the Red LED to on
 *
 * @param   None    
 *
 * @return  void
 ****************************************************************************************
 */
static void red_led_on()
{
    if (LED_STATE_OFF) {
        GPIO_SetInactive(KBD_RED_LED_PORT,      KBD_RED_LED_PIN);       // red: low - on
    } else {
        GPIO_SetActive  (KBD_RED_LED_PORT,      KBD_RED_LED_PIN);       // red: high - on
    }
    red_led_st = LED_ON;
}
/**
 ****************************************************************************************
 * @brief Sets the Green LED to blink
 *
 * @param   None    
 *
 * @return  void
 ****************************************************************************************
 */
static void green_led_blink()
{
    if (LED_STATE_OFF) {
        GPIO_SetInactive(KBD_GREEN_LED_PORT,    KBD_GREEN_LED_PIN);     // green: low - on
    } else {
        GPIO_SetActive  (KBD_GREEN_LED_PORT,    KBD_GREEN_LED_PIN);     // green: high - on
    }
    green_led_st = BLINK_LED_IS_ON__TURN_OFF;
}
/**
 ****************************************************************************************
 * @brief Sets the Green LED to on
 *
 * @param   None    
 *
 * @return  void
 ****************************************************************************************
 */
static void green_led_on()
{
    if (LED_STATE_OFF) {
        GPIO_SetInactive(KBD_GREEN_LED_PORT,    KBD_GREEN_LED_PIN);     // green: low - on
    } else {
        GPIO_SetActive  (KBD_GREEN_LED_PORT,    KBD_GREEN_LED_PIN);     // green: high - on
    }
    green_led_st = LED_ON;
}
/**
 ****************************************************************************************
 * @brief Sets the Red LED to off
 *
 * @param   None    
 *
 * @return  void
 ****************************************************************************************
 */
static void red_led_off()
{
    high_priority_indications_active = false;
    if (LED_STATE_OFF) {
        GPIO_SetActive  (KBD_RED_LED_PORT,      KBD_RED_LED_PIN);       // red: high - off
    } else {
        GPIO_SetInactive(KBD_RED_LED_PORT,      KBD_RED_LED_PIN);       // red: low - off
    }
    red_led_st = LED_OFF;
}
Exemple #11
0
void app_proxr_port_reinit(GPIO_PORT port, GPIO_PIN pin)
{
    app_proxr_init(port, pin);

	if(alert_state.blink_toggle == 1){
        GPIO_SetActive( alert_state.port, alert_state.pin);
    }
	else{
        GPIO_SetInactive( alert_state.port, alert_state.pin);
	}
	
}
Exemple #12
0
void app_batt_alert_start(void)
{
	batt_alert_en = 1;

    if (bat_lvl_alert_used )
        GPIO_SetActive( bat_led_port, bat_led_pin);

	bat_led_state = 1;
    
    ke_timer_clear(APP_BATT_ALERT_TIMER, TASK_APP);
	app_timer_set(APP_BATT_ALERT_TIMER, TASK_APP, 200);
    
}
Exemple #13
0
int app_proxr_timer_handler(ke_msg_id_t const msgid,
                                   void const *param,
                                   ke_task_id_t const dest_id,
                                   ke_task_id_t const src_id)
{

    if (alert_state.lvl != PROXR_ALERT_NONE)
    {
        if (alert_state.lvl == PROXR_ALERT_HIGH)
        {
            alert_state.blink_toggle =  1;
            app_timer_set(APP_PXP_TIMER, dest_id, alert_state.blink_timeout);
            GPIO_SetActive( alert_state.port, alert_state.pin);
            app_proxr_beep();
            GPIO_SetInactive(alert_state.port, alert_state.pin);
            alert_state.blink_toggle = 0;
        }
        else
        {
            if (alert_state.blink_toggle)
            {
               
                GPIO_SetInactive( alert_state.port, alert_state.pin);
                alert_state.blink_toggle = 0;
                app_timer_set(APP_PXP_TIMER, dest_id, alert_state.blink_timeout);
            }
            else
            {
                GPIO_SetActive( alert_state.port, alert_state.pin);
                alert_state.blink_toggle = 1;
                app_timer_set(APP_PXP_TIMER, dest_id, 2);
            }
        }
        
        app_timer_set(APP_PXP_TIMER, dest_id, alert_state.blink_timeout);
    }
		
    return (KE_MSG_CONSUMED);
}
void app_sample128_start_leds(void)
{
		if(1 == leds_state.flag)
		{
        //GPIO_SetActive( leds_state.port_led3, leds_state.pin_led3);
			  GPIO_SetActive(leds_state.port_led4, leds_state.pin_led4);
			  //GPIO_SetInactive(leds_state.port_led4, leds_state.pin_led4);
			  GPIO_SetInactive( leds_state.port_led3, leds_state.pin_led3);
			  //GPIO_ConfigurePin( GPIO_LED3_PORT, GPIO_LED3_PIN, OUTPUT, PID_GPIO, true );
			  
    }
	  else if(0 == leds_state.flag)
		{
        GPIO_SetInactive(leds_state.port_led4, leds_state.pin_led4);
			  //GPIO_SetInactive( leds_state.port_led3, leds_state.pin_led3);
			  GPIO_SetActive( leds_state.port_led3, leds_state.pin_led3);
			  //GPIO_ConfigurePin( GPIO_LED3_PORT, GPIO_LED3_PIN, OUTPUT, PID_GPIO, false );
			  //GPIO_ConfigurePin( GPIO_LED3_PORT, GPIO_LED3_PIN, OUTPUT, PID_GPIO, false );
	      //GPIO_ConfigurePin( GPIO_LED4_PORT, GPIO_LED4_PIN, OUTPUT, PID_GPIO, false );
			
			  
	  }
}
Exemple #15
0
/*
 * Name         : GPIO_ConfigurePin - Combined function to set the state
 *                                     and the type and mode of the GPIO pin 
 *
 * Scope        : PUBLIC
 *
 * Arguments    : port - GPIO port
 *                pin  - pin
 *                mode - pin mode (input, output...)
 *                function - pin usage (GPIO, UART, SPI...)
 *                high - set to TRUE to set the pin into high else low
 *
 * Description  : Sets the GPIO state and then its type and mode
 *
 * Returns      : void
 *
 */
void GPIO_ConfigurePin( GPIO_PORT port, GPIO_PIN pin, GPIO_PUPD mode, GPIO_FUNCTION function,
						 const bool high )
{
#if DEVELOPMENT__NO_OTP
    if ( !(GPIO_status & ( ((uint64_t)1 << pin) << (port * 16) )) )
                __asm("BKPT #0\n"); // this pin has not been previously reserved!        
#endif    
    
    if (high)
        GPIO_SetActive( port, pin );
    else
        GPIO_SetInactive( port, pin );
    
	GPIO_SetPinFunction( port, pin, mode, function );
}
Exemple #16
0
void app_batt_port_reinit(void)
{
    
    if (bat_lvl_alert_used)
    {
        if(bat_led_state == 1){
            GPIO_SetActive( bat_led_port, bat_led_pin);
        }
        else{
            GPIO_SetInactive( bat_led_port, bat_led_pin);
        }
    }


}
Exemple #17
0
void app_proxr_alert_start(uint8_t lvl)
{
	
	alert_state.lvl = lvl;
	
	if (alert_state.lvl == PROXR_ALERT_MILD)
		alert_state.blink_timeout = 50;
	else
		alert_state.blink_timeout = 50;
	
	alert_state.blink_toggle = 1;
    GPIO_SetActive( alert_state.port, alert_state.pin);
	
    app_timer_set(APP_PXP_TIMER, TASK_APP, alert_state.blink_timeout);	
}
/**
 ****************************************************************************************
 * @brief  Handler of the Green LED Timer
 *
 * @param[in]   msgid
 * @param[in]   param 
 * @param[in]   dest_id
 * @param[in]   src_id 
 *
 * @return  KE_MSG_CONSUMED
 ****************************************************************************************
 */
int app_green_led_timer_handler(ke_msg_id_t const msgid,
                                void const *param,
                                ke_task_id_t const dest_id,
                                ke_task_id_t const src_id)
{
    if (!dbg_uses_led_pins() || !((GetWord16(SYS_STAT_REG) & DBG_IS_UP) == DBG_IS_UP)) {
        // GPIOs are not being used by the debugger                    
        switch(green_led_st) {
        case LED_OFF:
            green_led_off();
            break;
        
        case BLINK_LED_IS_ON__TURN_OFF:
            GPIO_SetActive(KBD_GREEN_LED_PORT, KBD_GREEN_LED_PIN); // high - off
            app_timer_set(APP_GREEN_LED_TIMER, TASK_APP, BLINK_GREEN_OFF);
            green_led_st = BLINK_LED_IS_OFF__TURN_ON;
            if ((GetBits16(ANA_STATUS_REG, BOOST_SELECTED) == 0x1) && 
                ((red_led_st == LED_OFF) || (red_led_st == BLINK_LED_IS_OFF__TURN_ON))) {
                    app_restore_sleep_mode(); // restore sleep
            }
            break;
            
        case BLINK_LED_IS_OFF__TURN_ON:
            green_led_blink();
            app_timer_set(APP_GREEN_LED_TIMER, TASK_APP, BLINK_GREEN_ON);
            leds_block_sleep();
            break;
        
        case LED_ON:
            green_led_off();
            if ((GetBits16(ANA_STATUS_REG, BOOST_SELECTED) == 0x1) &&
                ((red_led_st == LED_OFF) || (red_led_st == BLINK_LED_IS_OFF__TURN_ON))) {
                app_restore_sleep_mode(); // restore sleep
            }
            break;
        
        default:
            break;
        }
    }
 	
	return (KE_MSG_CONSUMED);
}
Exemple #19
0
/**
 ****************************************************************************************
 * @brief Write to 3-wire SPI
 * @param[in] registerIndex: Target address (A6..A0)
 * @param[in] valueToWrite: Value to write
 *
 * @return  Number of read bytes
 ****************************************************************************************
 */
void write_to_3wire_SPI_register(uint8_t registerIndex, uint8_t valueToWrite)
{
    GPIO_SetInactive(cs.port, cs.pin);                              // pull CS low

    GPIO_SetPinFunction( sdio.port, sdio.pin, OUTPUT, PID_SPI_DO);  // configure SDIO as output

    SetWord16(SPI_RX_TX_REG0, (uint16_t)(registerIndex | 0x80) );   // MSB set to HIGH - A6..A0 Address of register to write to
    do {
    } while (GetBits16(SPI_CTRL_REG,SPI_INT_BIT)==0);               // polling to wait for spi transmission

    SetWord16(SPI_CLEAR_INT_REG, 0);                                //Clear SPI_CTRL_REG[SPI_INT_BIT] interrupt

    SetWord16(SPI_RX_TX_REG0, (uint16_t)valueToWrite );             // write data
    do {
    } while (GetBits16(SPI_CTRL_REG,SPI_INT_BIT)==0);               // polling to wait for spi transmission

    SetWord16(SPI_CLEAR_INT_REG, 0);                                // Clear SPI_CTRL_REG[SPI_INT_BIT] interrupt

    GPIO_SetActive(cs.port, cs.pin);                                // set CS high
}
/**
****************************************************************************************
* @brief Handles timer timeout
* @return If the message was consumed or not.
****************************************************************************************
*/
int sample128_timer_handler(ke_msg_id_t const msgid,
																 struct gapm_cmp_evt const *param,
																 ke_task_id_t const dest_id,
																 ke_task_id_t const src_id)
{
	//uint8_t Tmpi;
	//my_newer2_addChar Tmp_Buff;
	//ke_timer_set(APP_SAMPLE128_TIMER,TASK_APP,Sample_LED_Blink);
	//sample128_placeholder++;
	/*
	struct sample128_upd_char2_req *req = KE_MSG_ALLOC(
																	SAMPLE128_UPD_CHAR2_REQ,
																	TASK_SAMPLE128,
																	TASK_APP,
																	sample128_upd_char2_req
																	 );
	*/
	sample128_LED++;
	if(sample128_LED%2==0)
	{
		GPIO_SetActive(GPIO_PORT_1,GPIO_PIN_0);
	}
	else
	{
		GPIO_SetInactive(GPIO_PORT_1,GPIO_PIN_0);
	}
	uart2_write("Hello",strlen("Hello"),NULL);
	
	//user_uart_write(&sample128_LED,1,NULL);
	/*
	for(Tmpi=0;Tmpi<characristic2_length;Tmpi++)
	{
		Tmp_Buff[Tmpi]=(uint8_t)(sample128_LED+Tmpi);
	}
	memcpy(&req->val,Tmp_Buff,sizeof(my_newer2_addChar));
	req->val = sample128_placeholder;
	req->conhdl = app_env.conhdl;
	ke_msg_send(req);
	*/
	return (KE_MSG_CONSUMED);
}
Exemple #21
0
int app_proxr_timer_handler(ke_msg_id_t const msgid,
                                   void const *param,
                                   ke_task_id_t const dest_id,
                                   ke_task_id_t const src_id)
{
		 
		if (alert_state.blink_toggle)
		{
            GPIO_SetInactive( alert_state.port, alert_state.pin);
			alert_state.blink_toggle = 0;
		}
		else
		{
            GPIO_SetActive( alert_state.port, alert_state.pin);
			alert_state.blink_toggle = 1;
		}
		
		ke_timer_set(APP_PXP_TIMER, dest_id, alert_state.blink_timeout);
		
    return (KE_MSG_CONSUMED);
}
Exemple #22
0
void app_batt_alert_stop(void)
{	
	batt_alert_en = 0;

    if (bat_lvl_alert_used)
    {
#ifdef CUSTOM_BATTERY_LEVEL_MEASUREMENTS___LED_IS_ACTIVE_LOW        
        GPIO_SetActive( bat_led_port, bat_led_pin);    
#else
        GPIO_SetInactive( bat_led_port, bat_led_pin);        
#endif //CUSTOM_BATTERY_LEVEL_MEASUREMENTS___LED_IS_ACTIVE_LOW    
    }
	ke_timer_clear(APP_BATT_ALERT_TIMER, TASK_APP);
    
#ifdef CUSTOM_BATTERY_LEVEL_MEASUREMENTS___BOOST_MODE_CONFIGURATION
    if (bat_led_state == 0)
        app_restore_sleep_mode(); 
#endif //CUSTOM_BATTERY_LEVEL_MEASUREMENTS___BOOST_MODE_CONFIGURATION
	
	bat_led_state = 0;


}
/**
 ****************************************************************************************
 * @brief Handles Battery Alert timer
 *
 * @param[in] msgid     Id of the message received.
 * @param[in] param     Pointer to the parameters of the message.
 * @param[in] dest_id   ID of the receiving task instance (TASK_GAP).
 * @param[in] src_id    ID of the sending task instance.
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int app_batt_alert_timer_handler(ke_msg_id_t const msgid,
                                        void const *param,
										ke_task_id_t const dest_id,
										ke_task_id_t const src_id)
{
    //Read LED GPIO state
    if(bat_lvl_alert_used)
    {		
		if (bat_led_state)
		{
            GPIO_SetInactive( bat_led_port, bat_led_pin);            	
			bat_led_state = 0;
			app_timer_set(APP_BATT_ALERT_TIMER, dest_id, 20);
		}
		else
		{
            GPIO_SetActive( bat_led_port, bat_led_pin);
			bat_led_state = 1;
			app_timer_set(APP_BATT_ALERT_TIMER, dest_id, 5);
		}
    }
		
    return (KE_MSG_CONSUMED);
}
Exemple #24
0
void spi3wire_cs_high (void)
{
    GPIO_SetActive(cs.port, cs.pin);                              // set CS high
}