static void drawMenu(Menu_T * menuP,int selItemRow) { int i; //Menu Title. SerialPrintf("\r\n%s\r\n",menuP->banner); for (i=0; i < 16; i++) { int num = menuP->menuList[i].selectionChar & MENUNUMBERMASK; if (menuP->menuList[i].displayedString == NULL) break; // Display the menu item. if (selItemRow == i)//selected menu item { Printf("*%X=%-s\r\n",num,menuP->menuList[i].displayedString); } else { Printf(" %X=%-s\r\n",num,menuP->menuList[i].displayedString); } } }
BT_RESPONSE BT_sendCommand(u8 uart_port, u8 *fmt, ...) { SerialFlush(uart_port); SerialPrintf(uart_port, fmt); //CDCprintf(fmt); Delayms(BT_DELAY); }
static bool ReceiveData ( void ) { bool wasAtLeastOneByteTransferred = false; for ( ; ; ) { uint32_t byteCountToWrite; uint8_t * const writePtr = s_usbRxBuffer.GetWritePtr( &byteCountToWrite ); if ( byteCountToWrite == 0 ) break; const uint32_t inUsbBufferCount = udi_cdc_get_nb_received_data(); if ( inUsbBufferCount == 0 ) break; const uint32_t toReceiveCount = MinFrom( inUsbBufferCount, byteCountToWrite ); const uint32_t remainingCount = udi_cdc_read_buf( writePtr, toReceiveCount ); assert( remainingCount <= toReceiveCount ); const size_t readCount = toReceiveCount - remainingCount; if ( readCount == 0 ) { assert( false ); break; } // Trace the full data received. if ( false ) { SerialPrintStr( "Data received:" EOL ); SerialPrintHexDump( writePtr, readCount, EOL ); } // Trace only the packet length. if ( false ) { SerialPrintf( "%u" EOL, unsigned( readCount ) ); } s_usbRxBuffer.CommitWrittenElements( readCount ); wasAtLeastOneByteTransferred = true; } return wasAtLeastOneByteTransferred; }
int main(int argc, char* argv[]) { unsigned int ser = SerialOpen(115200); //Open serial port with a 115200 baud rate int a = 0; SerialFlush(ser); //Clear TX and RX buffer, can be called periodically SerialPuts(ser,"Serial communication using the Sensorian Shield.\r\n"); SerialPrintf(ser,"You are using device number %d.\r\n",ser); SerialFlush(ser); while(1) { if(SerialDataAvail(ser)) { a = SerialGetchar(ser); SerialPrintf(ser,"You sent %c.\r\n",(char)(a)); if(a == 'b') break; } } SerialPrintf(ser,"Closing serial port ..."); SerialClose(ser); //Close serial port return 0; }
/** * @brief This function handles EXTI0 interrupt request. * @param None * @retval None */ void EXTI0_IRQHandler(void) { static uint8_t temp = 10; //Check if EXTI_Line0 is asserted if (EXTI_GetITStatus(EXTI_Line0) != RESET) { //GPIOB->ODR = (1 << temp); //color: red //GPIOD->ODR = 0xFFFF; //if (++temp >= 13){ // temp = 10; //} //restart = 1 // synchronize on next frame if (synchro_enable == 0){ start_frame_interrupt = 1; } row_interrupt_time = row_clock_counter + TIM_GetCounter(TIM2); } //we need to clear line pending bit manually EXTI_ClearITPendingBit(EXTI_Line0); #ifdef DEBUG SerialPrintf("interrupt=\r\n"); #endif }
const char * CGenericSerialConsole::AddChar ( const uint8_t c, uint32_t * const retCmdLen ) { // Trace the incoming characters. if ( false ) { if ( IsPrintableAscii(c) ) SerialPrintf( "0x%02X (%3u, %c)" DBG_EOL, c, c, c ); else SerialPrintf( "0x%02X (%3u)" DBG_EOL, c, c ); } bool isCmdReady = false; switch ( m_state ) { case stIdle: isCmdReady = ProcessChar( c ); break; case stEscapeReceived: if ( c == '[' ) // CSI (0x5B) { m_state = stEscapeBracketReceived; } else { Bell(); m_state = stIdle; } break; case stEscapeBracketReceived: ProcessCharAfterEscapeBracket( c ); break; default: assert( false ); break; } if ( false ) { SerialPrintf( "Char: 0x%02X, cmd begin: %u, end: %u, len: %u, pos: %u" DBG_EOL, c, unsigned( m_cmdBeginPos ), unsigned( m_cmdEndPos ), unsigned( GetCircularDistance( m_cmdBeginPos, m_cmdEndPos, BUF_LEN ) ), unsigned( m_cursorPos ) ); } if ( isCmdReady ) { assert( m_cmdBeginPos < BUF_LEN ); assert( m_cmdEndPos < BUF_LEN ); m_buffer[ m_cmdEndPos ] = 0; const uint32_t cmdLen = GetCircularDistance( m_cmdBeginPos, m_cmdEndPos, BUF_LEN ); char * const first = &m_buffer[0]; char * const last = &m_buffer[BUF_LEN]; char * const middle = &m_buffer[m_cmdBeginPos]; std::rotate( first, middle, last ); assert( cmdLen < BUF_LEN ); m_cmdBeginPos = cmdLen; m_cmdEndPos = cmdLen; m_cursorPos = cmdLen; // SerialPrint( "Command ready." DBG_EOL ); assert( strlen( m_buffer ) == cmdLen ); *retCmdLen = cmdLen; return m_buffer; } else { *retCmdLen = 0; return NULL; } }