Default Demo Firmware for MAX32625NEXPAQ development module

Dependencies:   nexpaq_mdk

nexpaq tile code to be used with IO_Demo

Committer:
switches
Date:
Sat Feb 04 03:33:25 2017 +0000
Revision:
2:3474351b0eec
Parent:
1:5fb525e83780
Replaced development library with official mbed libarary

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:088641a122ff 1 #include "mbed.h"
switches 0:088641a122ff 2 #include "nexpaq_mdk.h"
switches 0:088641a122ff 3
switches 0:088641a122ff 4 PwmOut ledR(P2_4);
switches 0:088641a122ff 5 PwmOut ledG(P2_5);
switches 0:088641a122ff 6 PwmOut ledB(P2_6);
switches 0:088641a122ff 7 AnalogIn aIn0(AIN_0);
switches 0:088641a122ff 8 AnalogIn aIn1(AIN_1);
switches 0:088641a122ff 9 AnalogIn aIn2(AIN_2);
switches 0:088641a122ff 10 AnalogIn aIn3(AIN_3);
switches 0:088641a122ff 11 AnalogIn aIn4(AIN_4);
switches 0:088641a122ff 12 AnalogIn aIn5(AIN_5);
switches 0:088641a122ff 13 DigitalInOut digPin[] = {DigitalInOut(P0_1),DigitalInOut(P0_0),DigitalInOut(P1_2),DigitalInOut(P1_1),
switches 0:088641a122ff 14 DigitalInOut(P1_0),DigitalInOut(P1_3),DigitalInOut(P1_7),DigitalInOut(P1_6),
switches 0:088641a122ff 15 DigitalInOut(P3_0),DigitalInOut(P3_1),DigitalInOut(P3_4),DigitalInOut(P3_5),
switches 0:088641a122ff 16 DigitalInOut(P0_2),DigitalInOut(P0_3),DigitalInOut(P4_0),DigitalInOut(P4_1)
switches 0:088641a122ff 17 };
switches 0:088641a122ff 18
switches 0:088641a122ff 19 /***** Definitions *****/
switches 0:088641a122ff 20 #define FUNCTION_TABLE_NUM 2
switches 0:088641a122ff 21 #define UUID_NUM 16 // UUID number is 16, don't change it
switches 0:088641a122ff 22 #define LOOP_DELAY 1000
switches 0:088641a122ff 23
switches 0:088641a122ff 24 /***** Globals *****/
switches 0:088641a122ff 25 void my_function_CMD_2700(unsigned char *pData, unsigned char len);
switches 0:088641a122ff 26 void my_function_CMD_2702(unsigned char *pData, unsigned char len);
switches 0:088641a122ff 27 const MDK_REGISTER_CMD my_cmd_func_table[FUNCTION_TABLE_NUM] = {
switches 0:088641a122ff 28 {0x2700, my_function_CMD_2700}, // Command -> function
switches 0:088641a122ff 29 {0x2702, my_function_CMD_2702}, // Command -> function
switches 0:088641a122ff 30 };
switches 0:088641a122ff 31
switches 0:088641a122ff 32 unsigned char dataOut[10];
switches 0:088641a122ff 33
switches 0:088641a122ff 34 /***** Functions *****/
switches 0:088641a122ff 35 void my_function_CMD_2700(unsigned char *pData, unsigned char len)
switches 0:088641a122ff 36 {
switches 0:088641a122ff 37 unsigned char response = 0x00;
switches 0:088641a122ff 38 ledR = 1.0f - (pData[0] / 255.0f);
switches 0:088641a122ff 39 ledG = 1.0f - (pData[1] / 255.0f);
switches 0:088641a122ff 40 ledB = 1.0f - (pData[2] / 255.0f);
switches 0:088641a122ff 41 np_api_upload(0x2701, &response, 1);
switches 0:088641a122ff 42 }
switches 0:088641a122ff 43
switches 0:088641a122ff 44 void my_function_CMD_2702(unsigned char *pData, unsigned char len)
switches 0:088641a122ff 45 {
switches 0:088641a122ff 46 unsigned char response = 0x00;
switches 0:088641a122ff 47 int pinIndex = pData[0];
switches 0:088641a122ff 48 int pinMode = pData[1];
switches 0:088641a122ff 49 switch(pinMode) {
switches 0:088641a122ff 50 case 0:
switches 0:088641a122ff 51 case 1:
switches 0:088641a122ff 52 digPin[pinIndex].mode(PullNone);
switches 0:088641a122ff 53 digPin[pinIndex].input();
switches 0:088641a122ff 54 break;
switches 0:088641a122ff 55 case 2:
switches 0:088641a122ff 56 digPin[pinIndex].mode(PullDown);
switches 0:088641a122ff 57 digPin[pinIndex].input();
switches 0:088641a122ff 58 break;
switches 0:088641a122ff 59 case 3:
switches 0:088641a122ff 60 digPin[pinIndex].mode(PullUp);
switches 0:088641a122ff 61 digPin[pinIndex].input();
switches 0:088641a122ff 62 break;
switches 0:088641a122ff 63 case 4:
switches 0:088641a122ff 64 digPin[pinIndex]=0;
switches 0:088641a122ff 65 digPin[pinIndex].output();
switches 0:088641a122ff 66 break;
switches 0:088641a122ff 67 case 5:
switches 0:088641a122ff 68 digPin[pinIndex]=1;
switches 0:088641a122ff 69 digPin[pinIndex].output();
switches 0:088641a122ff 70 break;
switches 0:088641a122ff 71 }
switches 0:088641a122ff 72 np_api_upload(0x2703, &response, 1);
switches 0:088641a122ff 73 }
switches 0:088641a122ff 74
switches 0:088641a122ff 75 void sendStatus()
switches 0:088641a122ff 76 {
switches 0:088641a122ff 77 np_api_upload(0x2800, dataOut, 10);
switches 0:088641a122ff 78 }
switches 0:088641a122ff 79
switches 0:088641a122ff 80 /******************************************************************************/
switches 0:088641a122ff 81 void app_setup()
switches 0:088641a122ff 82 {
switches 0:088641a122ff 83 int i = 0;
switches 0:088641a122ff 84 // np_api_set_app_version(0, 0, 3);
switches 0:088641a122ff 85 if ( np_api_register((MDK_REGISTER_CMD*)my_cmd_func_table, FUNCTION_TABLE_NUM) == MDK_REGISTER_FAILD ) {
switches 0:088641a122ff 86 // Register failed handle code
switches 0:088641a122ff 87 }
switches 0:088641a122ff 88 ledR = 1.0f;
switches 0:088641a122ff 89 ledG = 1.0f;
switches 0:088641a122ff 90 ledB = 1.0f;
switches 0:088641a122ff 91 for (i = 0; i < 16; i++) {
switches 0:088641a122ff 92 digPin[i].mode(PullUp);
switches 0:088641a122ff 93 digPin[i].input();
switches 0:088641a122ff 94 }
switches 0:088641a122ff 95 for (i = 0; i < 10; i++) {
switches 0:088641a122ff 96 dataOut[i] = 0xFF;
switches 0:088641a122ff 97 }
switches 0:088641a122ff 98 }
switches 0:088641a122ff 99
switches 0:088641a122ff 100 void app_loop()
switches 0:088641a122ff 101 {
switches 0:088641a122ff 102 int anaData;
switches 1:5fb525e83780 103 anaData = aIn4.read_u16();
switches 1:5fb525e83780 104 dataOut[0] = anaData;
switches 1:5fb525e83780 105 dataOut[1] = anaData>>8;
switches 1:5fb525e83780 106 anaData = aIn5.read_u16();
switches 1:5fb525e83780 107 dataOut[2] = anaData;
switches 1:5fb525e83780 108 dataOut[3] = anaData>>8;
switches 0:088641a122ff 109 anaData = aIn2.read_u16();
switches 1:5fb525e83780 110 anaData = anaData/10;
switches 0:088641a122ff 111 dataOut[4] = anaData;
switches 0:088641a122ff 112 dataOut[5] = anaData>>8;
switches 0:088641a122ff 113 anaData = aIn3.read_u16();
switches 1:5fb525e83780 114 anaData = anaData/10;
switches 0:088641a122ff 115 dataOut[6] = anaData;
switches 0:088641a122ff 116 dataOut[7] = anaData>>8;
switches 0:088641a122ff 117
switches 0:088641a122ff 118 dataOut[8] = (digPin[7].read()<<7) +
switches 0:088641a122ff 119 (digPin[6].read()<<6) +
switches 0:088641a122ff 120 (digPin[5].read()<<5) +
switches 0:088641a122ff 121 (digPin[4].read()<<4) +
switches 0:088641a122ff 122 (digPin[3].read()<<3) +
switches 0:088641a122ff 123 (digPin[2].read()<<2) +
switches 0:088641a122ff 124 (digPin[1].read()<<1) +
switches 0:088641a122ff 125 (digPin[0].read());
switches 0:088641a122ff 126 dataOut[9] = (digPin[15].read()<<7) +
switches 0:088641a122ff 127 (digPin[14].read()<<6) +
switches 0:088641a122ff 128 (digPin[13].read()<<5) +
switches 0:088641a122ff 129 (digPin[12].read()<<4) +
switches 0:088641a122ff 130 (digPin[11].read()<<3) +
switches 0:088641a122ff 131 (digPin[10].read()<<2) +
switches 0:088641a122ff 132 (digPin[9].read()<<1) +
switches 0:088641a122ff 133 (digPin[8].read());
switches 0:088641a122ff 134 sendStatus();
switches 0:088641a122ff 135 }
switches 0:088641a122ff 136
switches 0:088641a122ff 137 int main(void)
switches 0:088641a122ff 138 {
switches 0:088641a122ff 139 np_api_init();
switches 0:088641a122ff 140 app_setup();
switches 0:088641a122ff 141 np_api_start();
switches 0:088641a122ff 142 while(1) {
switches 0:088641a122ff 143 app_loop();
switches 0:088641a122ff 144 np_api_bsl_chk();
switches 0:088641a122ff 145 Thread::wait(LOOP_DELAY);
switches 0:088641a122ff 146 }
switches 0:088641a122ff 147 return 0;
switches 0:088641a122ff 148 }