/*lint -save -e970 Disable MISRA rule (6.3) checking. */ int main(void) /*lint -restore Enable MISRA rule (6.3) checking. */ { /* Write your local variable definition here */ /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ /* Write your code here */ /* For example: for(;;) { } */ for(;;) { LEDG_Neg(); WAIT1_Waitms(100); } /*** Don't write any code pass this line, or it will be deleted during code generation. ***/ /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/ #ifdef PEX_RTOS_START PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */ #endif /*** End of RTOS startup code. ***/ /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/ for(;;){} /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/ } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
void APP_Run(void) { DHTxx_ErrorCode res; uint16_t temperature, humidity; CLS1_ConstStdIOType *io = CLS1_GetStdio(); uint8_t buf[48]; #if DHTxx_SENSOR_TYPE_IS_DHT11 CLS1_SendStr("DHT11 Sensor Demo:\r\n", io->stdErr); #else CLS1_SendStr("DHT22 Sensor Demo:\r\n", io->stdErr); #endif WAIT1_Waitms(1000); /* wait one second after power-up to get the sensor stable */ for(;;) { res = DHTxx_Read(&temperature, &humidity); if (res!=DHTxx_OK) { /* error */ LEDR_Neg(); /* indicate error with red LED */ /* write error message */ CLS1_SendStr("ERROR: ", io->stdErr); CLS1_SendStr(DHTxx_GetReturnCodeString(res), io->stdErr); CLS1_SendStr("\r\n", io->stdErr); } else { /* ok! */ LEDG_Neg(); /* write data values */ UTIL1_strcpy(buf, sizeof(buf), "Temperature "); UTIL1_strcatNum32sDotValue100(buf, sizeof(buf), (int32_t)temperature); UTIL1_strcat(buf, sizeof(buf), "°C, Humidity "); UTIL1_strcatNum32sDotValue100(buf, sizeof(buf), (int32_t)humidity); UTIL1_strcat(buf, sizeof(buf), "%\r\n"); CLS1_SendStr(buf, io->stdOut); } WAIT1_Waitms(DHTxx_SENSOR_PERIOD_MS); /* can only read sensor values with a certain frequency! */ } }
static portTASK_FUNCTION(ShellTask, pvParameters) { #if PL_HAS_SD_CARD bool cardMounted = FALSE; static FAT1_FATFS fileSystemObject; #endif unsigned char buf[48]; (void)pvParameters; /* not used */ buf[0] = '\0'; (void)CLS1_ParseWithCommandTable((unsigned char*)CLS1_CMD_HELP, CLS1_GetStdio(), CmdParserTable); for(;;) { #if PL_HAS_SD_CARD (void)FAT1_CheckCardPresence(&cardMounted, 0 /* volume */, &fileSystemObject, CLS1_GetStdio()); if (cardMounted) { //SD_GreenLed_On(); //SD_RedLed_Off(); } else { //SD_GreenLed_Off(); //SD_RedLed_On(); } #endif (void)CLS1_ReadAndParseWithCommandTable(buf, sizeof(buf), CLS1_GetStdio(), CmdParserTable); FRTOS1_vTaskDelay(50/portTICK_RATE_MS); LEDG_Neg(); } }
static void CDC_Run(void) { int i; uint32_t val = 0; unsigned char buf[16]; for(;;) { while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) { /* device not enumerated */ LEDR_Neg(); LEDG_Off(); WAIT1_Waitms(10); } LEDR_Off(); LEDG_Neg(); if (CDC1_GetCharsInRxBuf()!=0) { i = 0; while( i<sizeof(in_buffer)-1 && CDC1_GetChar(&in_buffer[i])==ERR_OK ) { i++; } in_buffer[i] = '\0'; (void)CDC1_SendString((unsigned char*)"echo: "); (void)CDC1_SendString(in_buffer); UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"val: "); UTIL1_strcatNum32u(buf, sizeof(buf), val); UTIL1_strcat(buf, sizeof(buf), (unsigned char*)"\r\n"); (void)CDC1_SendString(buf); val++; } else { WAIT1_Waitms(10); } } }
void APP_Run(void) { int cnt=0; /* counter to slow down LED blinking */ for(;;) { WAIT1_Waitms(10); cnt++; if (HIDM1_App_Task()==ERR_BUSOFF) { if ((cnt%128)==0) { /* just slow down blinking */ LEDG_Off(); LEDR_Neg(); } } else { if ((cnt%128)==0) { /* just slow down blinking */ LEDR_Off(); LEDG_Neg(); } if (SW2_GetVal()==0) { /* button pressed */ WAIT1_Waitms(100); /* wait for debouncing */ if (SW2_GetVal()==0) { /* still pressed */ //(void)HIDM1_Send(0, 8, 8); /* raw move message */ //(void)HIDM1_Send(HIDM1_MOUSE_LEFT, 0, 0); /* send left mouse button */ //(void)HIDM1_Send(0, 0, 0); /* send release button message */ //(void)HIDM1_Move(-8, 0); /* moving the cursor up */ //HIDM1_Click(HIDM1_MOUSE_LEFT); /* left mouse click */ HIDM1_Click(HIDM1_MOUSE_RIGHT); /* right mouse click */ } while(SW2_GetVal()==0) {} /* wait until button is released */ } } } }
static void CDC_Run(void) { int i; for(;;) { while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) { /* device not enumerated */ LEDR_Neg(); LEDG_Off(); WAIT1_Waitms(10); } LEDR_Off(); LEDG_Neg(); if (CDC1_GetCharsInRxBuf()!=0) { i = 0; while( i<sizeof(in_buffer)-1 && CDC1_GetChar(&in_buffer[i])==ERR_OK ) { i++; } in_buffer[i] = '\0'; (void)CDC1_SendString((unsigned char*)"echo: "); (void)CDC1_SendString(in_buffer); (void)CDC1_SendString((unsigned char*)"\r\n"); } else { WAIT1_Waitms(10); } } }
void blink_green(const int n) { int i; i = 0; for (i = 0; i < (2*n); i++) { LEDG_Neg(); WAIT1_Waitms(BLINKTIME); } LEDG_Off(); }
static portTASK_FUNCTION(ShellTask, pvParameters) { unsigned char buf[32]; (void)pvParameters; /* not used */ buf[0] = '\0'; (void)CLS1_ParseWithCommandTable((unsigned char*)CLS1_CMD_HELP, CLS1_GetStdio(), CmdParserTable); for(;;) { (void)CLS1_ReadAndParseWithCommandTable(buf, sizeof(buf), CLS1_GetStdio(), CmdParserTable); FRTOS1_vTaskDelay(50/portTICK_RATE_MS); LEDG_Neg(); } }
void switchLEDs(unsigned char ch) { switch (ch) { case 'r': LEDR_Neg(); break; case 'g': LEDG_Neg(); break; case 'b': LEDB_Neg(); break; default: LED_Neg(); break; } }
static portTASK_FUNCTION(ShellTask, pvParameters) { bool cardMounted = FALSE; static FAT1_FATFS fileSystemObject; unsigned char buf[48]; (void)pvParameters; /* not used */ buf[0] = '\0'; (void)CLS1_ParseWithCommandTable((unsigned char*)CLS1_CMD_HELP, CLS1_GetStdio(), CmdParserTable); for(;;) { (void)FAT1_CheckCardPresence(&cardMounted, 0 /* volume */, &fileSystemObject, CLS1_GetStdio()); (void)CLS1_ReadAndParseWithCommandTable(buf, sizeof(buf), CLS1_GetStdio(), CmdParserTable); FRTOS1_vTaskDelay(10/portTICK_RATE_MS); LEDG_Neg(); } }
static void CDC_Run(void) { int i, cnt = 0; uint32_t val = 0; unsigned char buf[16]; (void)CDC1_SendString((unsigned char*)"Hello world from the KL25Z with USB CDC\r\n"); for(;;) { while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) { /* device not enumerated */ LEDR_Neg(); LEDG_Off(); WAIT1_Waitms(10); } LEDR_Off(); LEDG_Neg(); if (CDC1_GetCharsInRxBuf()!=0) { i = 0; while( i<sizeof(in_buffer)-1 && CDC1_GetChar(&in_buffer[i])==ERR_OK ) { i++; } in_buffer[i] = '\0'; (void)CDC1_SendString((unsigned char*)"echo: "); (void)CDC1_SendString(in_buffer); UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"val: "); UTIL1_strcatNum32u(buf, sizeof(buf), val); UTIL1_strcat(buf, sizeof(buf), (unsigned char*)"\r\n"); (void)CDC1_SendString(buf); val++; } else { WAIT1_Waitms(10); cnt++; if ((cnt%1024)==0) { /* from time to time, write some text */ (void)CDC1_SendString((unsigned char*)"Type some text and it will echo.\r\n"); CDC1_SendBlock((unsigned char*)"hello?\r\n", sizeof("hello?\r\n")-1); } } } }
static void CDC_Run(void) { unsigned char buf[32]; for(;;) { while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) { /* device not enumerated */ LEDR_Neg(); LEDG_Off(); WAIT1_Waitms(10); } LEDR_Off(); LEDG_Neg(); if (CDC1_GetCharsInRxBuf()!=0) { CDC1_ClearRxBuffer(); /* discard incoming buffer */ UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"time on hours: "); UTIL1_strcatNum32u(buf, sizeof(buf), Time_On_Hours); UTIL1_strcat(buf, sizeof(buf), (unsigned char*)"\r\n"); (void)CDC1_SendString(buf); Time_On_Hours++; } else { WAIT1_Waitms(10); } } }
void APP_Run(void) { int cnt=0; /* counter to slow down LED blinking */ for(;;) { WAIT1_Waitms(10); cnt++; if (SW1_GetVal()==0) { /* button pressed */ WAIT1_Waitms(100); /* wait for debouncing */ if (SW1_GetVal()==0) { /* still pressed */ #if 1 /* send a string */ //(void)HIDK1_SendStr((unsigned char*)"SW1 press "); /* send a string */ #endif #if 0 /* send print screen */ //HIDK1_Send(MODIFERKEYS_NONE, KEY_PRINTSCREEN); //HIDK1_Send(MODIFERKEYS_NONE, KEY_NONE); /* release key */ #endif #if 0 /* send CTRL+ALT+DELETE */ HIDK1_Send(MODIFERKEYS_LEFT_CTRL|MODIFERKEYS_RIGHT_ALT, KEY_DELETE); HIDK1_Send(MODIFERKEYS_NONE, KEY_NONE); /* release key */ #endif } while(SW1_GetVal()==0) {} /* wait until button is released */ } if (HIDK1_App_Task()==ERR_OK) { /* run the USB application task: this will send the buffer */ if ((cnt%100)==0) { LEDR_Off(); LEDG_Neg(); /* blink green LED if connected */ } } else { if ((cnt%200)==0) { LEDG_Off(); LEDR_Neg(); /* blink red LED if not connected */ } } } }
static void LED_Neg(void) { LEDR_Neg(); LEDG_Neg(); LEDB_Neg(); }
void APP_Run(void) { int cnt=0; /* counter to slow down LED blinking */ uint8_t res; int16_t xyz[3]; res = MMA1_Init(); if (res!=ERR_OK) { Err(); } res = MMA1_SetFastMode(FALSE); if (res!=ERR_OK) { Err(); } res = MMA1_Enable(); /* enable accelerometer */ if (res!=ERR_OK) { Err(); } for(;;) { WAIT1_Waitms(10); /* implement 'air-mouse' movement */ xyz[0] = MMA1_GetX(); xyz[1] = MMA1_GetY(); xyz[3] = MMA1_GetZ(); /* y axis */ if (xyz[1]>AIR_THRESHOLD) { (void)HIDK2_Move(0, 2); /* moving the cursor left */ } else if (xyz[1]<-AIR_THRESHOLD) { (void)HIDK2_Move(0, -2); /* moving the cursor right */ } /* x axis */ if (xyz[0]>AIR_THRESHOLD) { (void)HIDK2_Move(-2, 0); /* moving the cursor up */ } else if (xyz[0]<-AIR_THRESHOLD) { (void)HIDK2_Move(2, 0); /* moving the cursor down */ } cnt++; if (HIDK2_App_Task()==ERR_BUSOFF) { if ((cnt%128)==0) { /* just slow down blinking */ LEDG_Off(); LEDR_Neg(); } } else { if ((cnt%128)==0) { /* just slow down blinking */ LEDR_Off(); LEDG_Neg(); } if (SW1_GetVal()==0) { /* button pressed */ WAIT1_Waitms(100); /* wait for debouncing */ if (SW1_GetVal()==0) { /* still pressed */ //(void)HIDK2_Send(0, 8, 8); /* raw move message */ //(void)HIDK2_Send(HIDK2_MOUSE_LEFT, 0, 0); /* send left mouse button */ //(void)HIDK2_Send(0, 0, 0); /* send release button message */ //(void)HIDK2_Move(-8, 0); /* moving the cursor up */ //HIDK2_Click(HIDK2_MOUSE_LEFT); /* left mouse click */ HIDK2_Click(HIDK2_MOUSE_RIGHT); /* right mouse click */ } while(SW1_GetVal()==0) {} /* wait until button is released */ } } } }