nkjnm

Dependencies:   MAX44000 nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Committer:
jowen
Date:
Mon Sep 19 09:06:46 2016 +0000
Revision:
2:3842948024ca
Parent:
0:b86eda0e990d
Child:
3:9d15891f9352
Add LED indication for debug

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 0:b86eda0e990d 1 #include "mbed.h"
nexpaq 0:b86eda0e990d 2 #include "nexpaq_mdk.h"
nexpaq 0:b86eda0e990d 3
jowen 2:3842948024ca 4 #ifdef __cplusplus
jowen 2:3842948024ca 5 extern "C" {
jowen 2:3842948024ca 6 #endif
jowen 2:3842948024ca 7 extern volatile uint8_t flag_jump_bsl;
jowen 2:3842948024ca 8 #ifdef __cplusplus
jowen 2:3842948024ca 9 }
jowen 2:3842948024ca 10 #endif
nexpaq 0:b86eda0e990d 11 DigitalOut ledR(P2_4, LED_OFF);
nexpaq 0:b86eda0e990d 12 DigitalOut ledG(P2_5, LED_OFF);
nexpaq 0:b86eda0e990d 13 DigitalOut ledB(P2_6, LED_OFF);
nexpaq 0:b86eda0e990d 14 DigitalIn button(P0_1, PullUp);
nexpaq 0:b86eda0e990d 15
nexpaq 0:b86eda0e990d 16 /***** Definitions *****/
nexpaq 0:b86eda0e990d 17 #define FUNCTION_TABLE_NUM 1
nexpaq 0:b86eda0e990d 18 #define UUID_NUM 16 //UUID number is 16, don't change it
nexpaq 0:b86eda0e990d 19 #define BUTTON_DEBOUNCE 5
nexpaq 0:b86eda0e990d 20 #define DBG_MSG
nexpaq 0:b86eda0e990d 21
nexpaq 0:b86eda0e990d 22 /***** Globals *****/
nexpaq 0:b86eda0e990d 23 void my_function_CMD_2700(unsigned char *pData, unsigned char len);
nexpaq 0:b86eda0e990d 24 const MDK_REGISTER_CMD my_cmd_func_table[FUNCTION_TABLE_NUM] = {
nexpaq 0:b86eda0e990d 25 {0x2700, my_function_CMD_2700}, // Command -> function
nexpaq 0:b86eda0e990d 26 };
nexpaq 0:b86eda0e990d 27
nexpaq 0:b86eda0e990d 28 int btnCnt = 0;
nexpaq 0:b86eda0e990d 29 int btnSts = 0;
nexpaq 0:b86eda0e990d 30 unsigned char btnPress = 0x01;
nexpaq 0:b86eda0e990d 31
nexpaq 0:b86eda0e990d 32 /***** Functions *****/
nexpaq 0:b86eda0e990d 33 void my_function_CMD_2700(unsigned char *pData, unsigned char len){
nexpaq 0:b86eda0e990d 34 unsigned char response = 0x00;
nexpaq 0:b86eda0e990d 35 ledR = (pData[0]>0) ? LED_ON : LED_OFF ;
nexpaq 0:b86eda0e990d 36 ledG = (pData[1]>0) ? LED_ON : LED_OFF ;
nexpaq 0:b86eda0e990d 37 ledB = (pData[2]>0) ? LED_ON : LED_OFF ;
nexpaq 0:b86eda0e990d 38 np_api_upload(0x2701, &response, 1);
nexpaq 0:b86eda0e990d 39 #ifdef DBG_MSG
nexpaq 0:b86eda0e990d 40 printf("LED Command Received\n\r");
nexpaq 0:b86eda0e990d 41 #endif
nexpaq 0:b86eda0e990d 42 }
nexpaq 0:b86eda0e990d 43
nexpaq 0:b86eda0e990d 44 /******************************************************************************/
nexpaq 0:b86eda0e990d 45 void app_setup(){
nexpaq 0:b86eda0e990d 46 // np_api_set_app_version(0, 0, 3);
nexpaq 0:b86eda0e990d 47 if ( np_api_register((MDK_REGISTER_CMD*)my_cmd_func_table, FUNCTION_TABLE_NUM) == MDK_REGISTER_FAILD ) {
nexpaq 0:b86eda0e990d 48 // Register failed handle code
nexpaq 0:b86eda0e990d 49 error("MDK Register Failed");
nexpaq 0:b86eda0e990d 50 }
nexpaq 0:b86eda0e990d 51 #ifdef DBG_MSG
nexpaq 0:b86eda0e990d 52 printf("MDK Commands Registered\n\r");
nexpaq 0:b86eda0e990d 53 #endif
nexpaq 0:b86eda0e990d 54 }
nexpaq 0:b86eda0e990d 55
nexpaq 0:b86eda0e990d 56 void app_loop() {
nexpaq 0:b86eda0e990d 57 if (btnSts) {
nexpaq 0:b86eda0e990d 58 btnCnt = (button) ? 0 : (btnCnt + 1);
nexpaq 0:b86eda0e990d 59 if (btnCnt >= BUTTON_DEBOUNCE) {
nexpaq 0:b86eda0e990d 60 np_api_upload(0x2800, &btnPress, 1);
nexpaq 0:b86eda0e990d 61 btnSts = !btnSts;
nexpaq 0:b86eda0e990d 62 btnCnt = 0;
nexpaq 0:b86eda0e990d 63 #ifdef DBG_MSG
nexpaq 0:b86eda0e990d 64 printf("Button Pressed\n\r");
nexpaq 0:b86eda0e990d 65 #endif
nexpaq 0:b86eda0e990d 66 }
nexpaq 0:b86eda0e990d 67 } else {
nexpaq 0:b86eda0e990d 68 btnCnt = (!button) ? 0 : (btnCnt + 1);
nexpaq 0:b86eda0e990d 69 if (btnCnt >= BUTTON_DEBOUNCE) {
nexpaq 0:b86eda0e990d 70 btnSts = !btnSts;
nexpaq 0:b86eda0e990d 71 btnCnt = 0;
nexpaq 0:b86eda0e990d 72 }
nexpaq 0:b86eda0e990d 73 }
nexpaq 0:b86eda0e990d 74 }
nexpaq 0:b86eda0e990d 75
nexpaq 0:b86eda0e990d 76 int main(void){
jowen 2:3842948024ca 77
jowen 2:3842948024ca 78 uint32_t cnt, i;
jowen 2:3842948024ca 79
jowen 2:3842948024ca 80 cnt = 500;
jowen 2:3842948024ca 81 ledR = 1;
jowen 2:3842948024ca 82 ledG = 0;
jowen 2:3842948024ca 83 ledB = 1;
jowen 2:3842948024ca 84
nexpaq 0:b86eda0e990d 85 np_api_init();
nexpaq 0:b86eda0e990d 86 app_setup();
nexpaq 0:b86eda0e990d 87 np_api_start();
jowen 2:3842948024ca 88 //Thread::wait(5000);
nexpaq 0:b86eda0e990d 89 while(1){
nexpaq 0:b86eda0e990d 90 app_loop();
nexpaq 0:b86eda0e990d 91 np_api_bsl_chk();
nexpaq 0:b86eda0e990d 92 Thread::wait(50);
jowen 2:3842948024ca 93
jowen 2:3842948024ca 94 if (cnt) {
jowen 2:3842948024ca 95 cnt--;
jowen 2:3842948024ca 96 if (cnt == 0) {
jowen 2:3842948024ca 97 ledR = 1;
jowen 2:3842948024ca 98 ledG = 1;
jowen 2:3842948024ca 99 ledB = 1;
jowen 2:3842948024ca 100 Thread::wait(50);
jowen 2:3842948024ca 101 cnt = 1000;
jowen 2:3842948024ca 102 //NVIC_SystemReset();
jowen 2:3842948024ca 103 }
jowen 2:3842948024ca 104 }
jowen 2:3842948024ca 105
jowen 2:3842948024ca 106 i = cnt%30;
jowen 2:3842948024ca 107 if (i == 10)
jowen 2:3842948024ca 108 {
jowen 2:3842948024ca 109 ledR = 1;
jowen 2:3842948024ca 110 ledG = 1;
jowen 2:3842948024ca 111 ledB = 1;
jowen 2:3842948024ca 112 }
jowen 2:3842948024ca 113 else if (i == 20){
jowen 2:3842948024ca 114 ledR = 1;
jowen 2:3842948024ca 115 ledG = 0;
jowen 2:3842948024ca 116 ledB = 1;
jowen 2:3842948024ca 117 }
jowen 2:3842948024ca 118 else if (i == 0) {
jowen 2:3842948024ca 119 ledR = 1;
jowen 2:3842948024ca 120 ledG = 1;
jowen 2:3842948024ca 121 ledB = 0;
jowen 2:3842948024ca 122 }
nexpaq 0:b86eda0e990d 123 }
jowen 2:3842948024ca 124
nexpaq 0:b86eda0e990d 125 return 0;
nexpaq 0:b86eda0e990d 126 }
nexpaq 0:b86eda0e990d 127