// // Callback function for HID application // void usbHidAppPoll(void) { // // Output keyboard LED status on LEDs 2-4 // if (hidData.keyboardOutReport.ledStatus & 0x01) { bspLedSet(BSP_LED_2); } else { bspLedClear(BSP_LED_2); } if (hidData.keyboardOutReport.ledStatus & 0x02) { bspLedSet(BSP_LED_3); } else { bspLedClear(BSP_LED_3); } if (hidData.keyboardOutReport.ledStatus & 0x04) { bspLedSet(BSP_LED_4); } else { bspLedClear(BSP_LED_4); } }
/**************************************************************************//** * @brief Main function of example. ******************************************************************************/ void main(void) { volatile uint32_t ui32Loop; // // Init LEDs (turned off) // bspLedInit(); // // Turn on LED1 and LED4 // bspLedSet(BSP_LED_1|BSP_LED_4); // // Infinite loop // while(1) { // // Toggle LED2 and LED3 // bspLedToggle(BSP_LED_2|BSP_LED_3); // // Simple wait // for(ui32Loop = 0; ui32Loop < 500000; ui32Loop++) { } } }
static void state_led_timer(void) { switch(app_state) { case APP_STATE_INIT: bspLedSet(BSP_LED_1); break; case APP_STATE_SCANNING: bspLedToggle(BSP_LED_1); WS_TIMER_SET(state_led_timer, 200); break; case APP_STATE_ASSOCIATING: case APP_STATE_AUTHENTICATING: bspLedClear(BSP_LED_1); bspLedToggle(BSP_LED_2); WS_TIMER_SET(state_led_timer, 200); break; case APP_STATE_CONNECTED: bspLedClear(BSP_LED_1); bspLedClear(BSP_LED_2); if (connected_led) bspLedSet(BSP_LED_3); else bspLedClear(BSP_LED_3); break; default: bspLedClear(BSP_LED_1); bspLedClear(BSP_LED_2); break; } }
/**************************************************************************//** * @brief Main function of example. ******************************************************************************/ void main(void) { uint8_t ui8KeyBm = 0; uint_fast16_t ui16Cnt = 0; uint8_t ui8Byte = APP_TX_BYTE; // // Initialize clocks and board I/O // bspInit(BSP_SYS_CLK_SPD); // // Set LED1 to indicate life // bspLedSet(BSP_LED_1); // // Initialize key driver // bspKeyInit(BSP_KEY_MODE_ISR); bspKeyIntEnable(BSP_KEY_SELECT|BSP_KEY_UP); // // Initialize UART to USB MCU // bspUartBufInit(pui8TxBuf, sizeof(pui8TxBuf), pui8RxBuf, sizeof(pui8RxBuf)); // // Application must register the UART interrupt handler // UARTIntRegister(BSP_UART_BASE, &appUartIsr); // // Open UART connection // if(bspUartOpen(eBaudRate115200) != BSP_UART_SUCCESS) { // // Failed to initialize UART handler // bspAssert(); } // // Initialize SPI interface to LCD, configure LCD, and display information. // bspSpiInit(BSP_SPI_CLK_SPD); lcdInit(); lcdBufferPrintStringAligned(0, "UART example", eLcdAlignCenter, eLcdPage0); lcdBufferInvertPage(0, 0,127, eLcdPage0); lcdBufferPrintString(0, "Baud rate :", 6, eLcdPage2); lcdBufferPrintIntAligned(0, bspUartBaudRateGet(), eLcdAlignRight, eLcdPage2); lcdBufferPrintString(0, "Format :", 6, eLcdPage3); lcdBufferPrintStringAligned(0, "8-N-1", eLcdAlignRight, eLcdPage3); lcdBufferPrintString(0, "Flow control:", 6, eLcdPage4); lcdBufferPrintStringAligned(0, "No", eLcdAlignRight, eLcdPage4); lcdBufferPrintStringAligned(0, "Transmit: UP key", eLcdAlignRight, eLcdPage6); lcdBufferPrintStringAligned(0, "SELECT to toggle mode", eLcdAlignCenter, eLcdPage7); lcdBufferInvertPage(0, 0,127, eLcdPage7); lcdSendBuffer(0); // // Enable global interrupts // IntMasterEnable(); while(1) { ui8KeyBm = bspKeyPushed(BSP_KEY_ALL); if(BSP_KEY_SELECT & ui8KeyBm) { // // Change mode // bRepeaterMode ^= 1; bspLedToggle(BSP_LED_3); // // Update LCD for the new mode // lcdBufferClearPart(0, 0,127, eLcdPage6, eLcdPage6); if(bRepeaterMode) { lcdBufferPrintStringAligned(0, "Repeater mode", eLcdAlignCenter, eLcdPage6); } else { lcdBufferPrintStringAligned(0, "Transmit: UP key", eLcdAlignCenter, eLcdPage6); } lcdSendBufferPart(0, 0,127, eLcdPage6, eLcdPage6); } // // Read data from UART RX buffer to application buffer // ui16Cnt = bspUartDataGet(pui8AppBuf, bspUartRxCharsAvail()); if(bRepeaterMode) { // // Repeater mode // if(ui16Cnt) { // // Send data from application buffer to UART TX buffer // bspUartDataPut(pui8AppBuf, ui16Cnt); } } else { // // Transmit mode // if(BSP_KEY_UP & ui8KeyBm) { // // Transmit a single character // bspUartDataPut(&ui8Byte, 1); } } } }
/******************************************************************************* * @fn main * * @brief Runs the main routine * * @param none * * @return none */ void main(void) { uint8 writeByte; // Initialize MCU and peripherals initMCU(); // Write radio registers (preferred settings from SmartRF Studio) registerConfig(); // Application specific registers // FIFO_THR = 120 // GPIO0 = RXFIFO_THR // GPIO2 = PKT_SYNC_RXTX // GPIO3 = PKT_SYNC_RXTX writeByte = INFINITE_PACKET_LENGTH_MODE; cc112xSpiWriteReg(CC112X_PKT_CFG0, &writeByte, 1); writeByte = 0x78; cc112xSpiWriteReg(CC112X_FIFO_CFG, &writeByte, 1); writeByte = 0x00; cc112xSpiWriteReg(CC112X_IOCFG0, &writeByte, 1); writeByte = 0x06; cc112xSpiWriteReg(CC112X_IOCFG2, &writeByte, 1); writeByte = 0x06; cc112xSpiWriteReg(CC112X_IOCFG3, &writeByte, 1); bspLedSet(BSP_LED_ALL); // Calibrate the radio according to the errata note manualCalibration(); // Connect ISR function to GPIO0 ioPinIntRegister(IO_PIN_PORT_1, GPIO0, &rxFifoAboveThresholdISR); // Interrupt on falling edge ioPinIntTypeSet(IO_PIN_PORT_1, GPIO0, IO_PIN_RISING_EDGE); // Clear interrupt ioPinIntClear(IO_PIN_PORT_1, GPIO0); // Enable interrupt ioPinIntEnable(IO_PIN_PORT_1, GPIO0); // Connect ISR function to GPIO2 ioPinIntRegister(IO_PIN_PORT_1, GPIO2, &syncReceivedISR); // Interrupt on falling edge ioPinIntTypeSet(IO_PIN_PORT_1, GPIO2, IO_PIN_RISING_EDGE); // Clear interrupt ioPinIntClear(IO_PIN_PORT_1, GPIO2); // Enable interrupt ioPinIntEnable(IO_PIN_PORT_1, GPIO2); // Set up interrupt on GPIO3 (PKT_SYNC_RXTX) ioPinIntRegister(IO_PIN_PORT_1, GPIO3, &packetReceivedISR); // Interrupt on falling edge ioPinIntTypeSet(IO_PIN_PORT_1, GPIO3, IO_PIN_FALLING_EDGE); printWelcomeMessage(); while (TRUE) { switch (state) { //------------------------------------------------------------------ case RX_START: //------------------------------------------------------------------ trxSpiCmdStrobe(CC112X_SRX); pBufferIndex = rxBuffer; // Disable interrupt on GPIO3 ioPinIntDisable(IO_PIN_PORT_1, GPIO3); state = RX_WAIT; //------------------------------------------------------------------ case RX_WAIT: //------------------------------------------------------------------ if (packetReceived) { packetReceived = FALSE; // Check CRC and update LCD if CRC OK if ((rxBuffer[packetLength + 3]) & CRC_OK) updateLcd(); // Change to infinite packet length mode pktFormat = INFINITE; writeByte = INFINITE_PACKET_LENGTH_MODE; cc112xSpiWriteReg(CC112X_PKT_CFG0, &writeByte, 1); state = RX_START; } break; //------------------------------------------------------------------ default: //------------------------------------------------------------------ break; } } }
/***************************************************************************//** * @brief Runs the main routine * * This function covers the main application code. * * @note Depending on the application, you can use either one or several * calls from the following functions from the SIGFOX Library: * * @note \li SfxSendFrame(message, length, NULL, NULL) : Send an Uplink frame * @note \li SfxSendFrame(message, length, ReceivedPayload, TRUE) : Downlink with ack * @note \li SfxSendBit( 0, NULL, NULL) : Send a bit * @note \li SfxSendOutOfBand() : Send OOB frame * @note \li SfxTxTestMode(nb_frames, channel_number) : Tx TestModeFrame activation ******************************************************************************/ void main(void) { SFX_error_t volatile err; // error returned from sigfox api functions. (For debug purpose) #if defined(AT_CMD) host_cmd_status_t hostCmdStatus; char cmd[40]; unsigned char length; #endif #if defined(PB_KEY) unsigned char buttonPressed; #endif //Initialize the memory dynamic_memory_init(); // Initialize MCU and Peripherals initMCU(); #ifdef __MSP430F5438A__ // Display welcome screen on LCD welcomeLCD(); #endif // Write the uplink and downlink frequencies if device is programmed for first time resetCF(); // SIGFOX library init err = SfxInit(); assert(SFX_ERR_NONE == err); // Infinite loop for(;;) { GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_PIN7); // GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN7); // P4OUT |= 0x00; P4OUT &= ~BIT7; #if defined(AT_CMD) // Detect Carriage Return in the string if(uartGetRxEndOfStr() == END_OF_LINE_DETECTED) { // Reset end of string detection uartResetRxEndOfStr(); // Get the input string and its length length = uartGetRxStrLength(); uartGetStr(cmd, length); // Parse the string to find AT commands hostCmdStatus = parseHostCmd((unsigned char *)cmd, length); assert(HOST_CMD_NOT_FOUND != hostCmdStatus); } #endif #if defined(PB_KEY) buttonPressed = bspKeyPushed(BSP_KEY_ALL); // Detect button push to send the message if((buttonPressed == BSP_KEY_SELECT) || (buttonPressed == BSP_KEY_UP)) { #if defined(__MSP430F5438A__) // Update LCD updateLCD(); // Toggle LED indicators bspLedClear(BSP_LED_3); bspLedClear(BSP_LED_4); #endif bspLedClear(BSP_LED_2); bspLedSet(BSP_LED_1); if(buttonPressed == BSP_KEY_UP) { // Send uplink only frame err = SfxSendFrame(message, sizeof(message), NULL, NULL); } else if(buttonPressed == BSP_KEY_SELECT) { // Send a bi-directional frame err = SfxSendFrame(message, sizeof(message), ReceivedPayload, TRUE); } // Reset button status buttonPressed = 0; #if defined (__MSP430F5438A__) // Clear LED1 bspLedClear(BSP_LED_1); // LED indicator for sigfox API error status if (err == SFX_ERR_NONE) { bspLedSet(BSP_LED_3); } else { bspLedSet(BSP_LED_4); } // Update LCD updateLCD(); #elif defined (__MSP430F5529__) if (err == SFX_ERR_NONE) { bspLedSet(BSP_LED_2); } else { bspLedClear(BSP_LED_2); } #endif // Increment in message message[11]++; } else { #if defined (__MSP430F5438A__) // Set LED2 bspLedSet(BSP_LED_2); #elif defined (__MSP430F5529__) // Clear LED1 bspLedClear(BSP_LED_1); #endif //MSP } #endif //INTERFACE } }
// yellow void leds_debug_on() { bspLedSet(BSP_LED_3); }
// green void leds_radio_on() { bspLedSet(BSP_LED_4); }
// orange void leds_sync_on() { bspLedSet(BSP_LED_2); }
// red void leds_error_on() { bspLedSet(BSP_LED_1); }
void leds_all_on() { bspLedSet(BSP_LED_ALL); }