Demo

Dependencies:   mbed

Committer:
nightseas
Date:
Wed Jul 08 17:50:18 2015 +0000
Revision:
0:3dac4f477e98
Child:
2:0ee90da44162
Basic Demo; Implement: Debug serial commander, Gas sensors, Temp&Rh sensor.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nightseas 0:3dac4f477e98 1 #include "SysConfig.h"
nightseas 0:3dac4f477e98 2
nightseas 0:3dac4f477e98 3 //On-board LED number
nightseas 0:3dac4f477e98 4 const int LED_NUM_MAX = 3;
nightseas 0:3dac4f477e98 5
nightseas 0:3dac4f477e98 6 //I2C for SHT20 & BMP180
nightseas 0:3dac4f477e98 7 I2C i2c_sen(PB_11, PB_10);
nightseas 0:3dac4f477e98 8
nightseas 0:3dac4f477e98 9 //USART2 to PC, USART1 to sensors & WiFi module
nightseas 0:3dac4f477e98 10 Serial uart_pc(SERIAL_TX, SERIAL_RX);
nightseas 0:3dac4f477e98 11 Serial uart_sen(PA_9, PA_10);
nightseas 0:3dac4f477e98 12
nightseas 0:3dac4f477e98 13 //LEDs on mother board and daughter board
nightseas 0:3dac4f477e98 14 DigitalOut led_mb(LED1, 0), led_db1_n(PB_1, 1), led_db2_n(PB_2, 1);
nightseas 0:3dac4f477e98 15
nightseas 0:3dac4f477e98 16 //GPIO for CD4052 serial mux control
nightseas 0:3dac4f477e98 17 DigitalOut smux_a(PB_14, 0), smux_b(PB_13, 0), smux_oe_n(PB_15, 1);
nightseas 0:3dac4f477e98 18
nightseas 0:3dac4f477e98 19
nightseas 0:3dac4f477e98 20 //Init board library
nightseas 0:3dac4f477e98 21 //--> Success return 0
nightseas 0:3dac4f477e98 22 int BoardLibInit(void)
nightseas 0:3dac4f477e98 23 {
nightseas 0:3dac4f477e98 24 //Init LED status
nightseas 0:3dac4f477e98 25 LedOnAll();
nightseas 0:3dac4f477e98 26
nightseas 0:3dac4f477e98 27 //Init debug & sensor UART
nightseas 0:3dac4f477e98 28 uart_pc.baud(115200);
nightseas 0:3dac4f477e98 29 uart_sen.baud(9600);
nightseas 0:3dac4f477e98 30
nightseas 0:3dac4f477e98 31 //Init sensor I2C
nightseas 0:3dac4f477e98 32 i2c_sen.frequency(100000);
nightseas 0:3dac4f477e98 33
nightseas 0:3dac4f477e98 34 //Init serial mux chip
nightseas 0:3dac4f477e98 35 SerialMuxDisable();
nightseas 0:3dac4f477e98 36 SerialMuxSel(0);
nightseas 0:3dac4f477e98 37
nightseas 0:3dac4f477e98 38 //Return 0 if success
nightseas 0:3dac4f477e98 39 return 0;
nightseas 0:3dac4f477e98 40 }
nightseas 0:3dac4f477e98 41
nightseas 0:3dac4f477e98 42 void SerialMuxSel(int ch)
nightseas 0:3dac4f477e98 43 {
nightseas 0:3dac4f477e98 44 switch(ch)
nightseas 0:3dac4f477e98 45 {
nightseas 0:3dac4f477e98 46 case 1:
nightseas 0:3dac4f477e98 47 smux_a = 1;
nightseas 0:3dac4f477e98 48 smux_b = 0;
nightseas 0:3dac4f477e98 49 break;
nightseas 0:3dac4f477e98 50
nightseas 0:3dac4f477e98 51 case 2:
nightseas 0:3dac4f477e98 52 smux_a = 0;
nightseas 0:3dac4f477e98 53 smux_b = 1;
nightseas 0:3dac4f477e98 54 break;
nightseas 0:3dac4f477e98 55
nightseas 0:3dac4f477e98 56 case 3:
nightseas 0:3dac4f477e98 57 smux_a = 1;
nightseas 0:3dac4f477e98 58 smux_b = 1;
nightseas 0:3dac4f477e98 59 break;
nightseas 0:3dac4f477e98 60
nightseas 0:3dac4f477e98 61
nightseas 0:3dac4f477e98 62 case 0:
nightseas 0:3dac4f477e98 63 default:
nightseas 0:3dac4f477e98 64 smux_a = 0;
nightseas 0:3dac4f477e98 65 smux_b = 0;
nightseas 0:3dac4f477e98 66 break;
nightseas 0:3dac4f477e98 67 }
nightseas 0:3dac4f477e98 68 }
nightseas 0:3dac4f477e98 69
nightseas 0:3dac4f477e98 70 void SerialMuxEnable(void)
nightseas 0:3dac4f477e98 71 {
nightseas 0:3dac4f477e98 72 smux_oe_n = 0;
nightseas 0:3dac4f477e98 73 }
nightseas 0:3dac4f477e98 74
nightseas 0:3dac4f477e98 75 void SerialMuxDisable(void)
nightseas 0:3dac4f477e98 76 {
nightseas 0:3dac4f477e98 77 smux_oe_n = 0;
nightseas 0:3dac4f477e98 78 }
nightseas 0:3dac4f477e98 79
nightseas 0:3dac4f477e98 80 void LedOn(int ch)
nightseas 0:3dac4f477e98 81 {
nightseas 0:3dac4f477e98 82 switch(ch)
nightseas 0:3dac4f477e98 83 {
nightseas 0:3dac4f477e98 84 case 0:
nightseas 0:3dac4f477e98 85 led_mb = 1;
nightseas 0:3dac4f477e98 86 break;
nightseas 0:3dac4f477e98 87
nightseas 0:3dac4f477e98 88 case 1:
nightseas 0:3dac4f477e98 89 led_db1_n = 0;
nightseas 0:3dac4f477e98 90 break;
nightseas 0:3dac4f477e98 91
nightseas 0:3dac4f477e98 92 case 2:
nightseas 0:3dac4f477e98 93 led_db2_n = 0;
nightseas 0:3dac4f477e98 94 break;
nightseas 0:3dac4f477e98 95
nightseas 0:3dac4f477e98 96 default:
nightseas 0:3dac4f477e98 97 break;
nightseas 0:3dac4f477e98 98 }
nightseas 0:3dac4f477e98 99 }
nightseas 0:3dac4f477e98 100
nightseas 0:3dac4f477e98 101 void LedOff(int ch)
nightseas 0:3dac4f477e98 102 {
nightseas 0:3dac4f477e98 103 switch(ch)
nightseas 0:3dac4f477e98 104 {
nightseas 0:3dac4f477e98 105 case 0:
nightseas 0:3dac4f477e98 106 led_mb = 0;
nightseas 0:3dac4f477e98 107 break;
nightseas 0:3dac4f477e98 108
nightseas 0:3dac4f477e98 109 case 1:
nightseas 0:3dac4f477e98 110 led_db1_n = 1;
nightseas 0:3dac4f477e98 111 break;
nightseas 0:3dac4f477e98 112
nightseas 0:3dac4f477e98 113 case 2:
nightseas 0:3dac4f477e98 114 led_db2_n = 1;
nightseas 0:3dac4f477e98 115 break;
nightseas 0:3dac4f477e98 116
nightseas 0:3dac4f477e98 117 default:
nightseas 0:3dac4f477e98 118 break;
nightseas 0:3dac4f477e98 119 }
nightseas 0:3dac4f477e98 120 }
nightseas 0:3dac4f477e98 121
nightseas 0:3dac4f477e98 122 void LedToggle(int ch)
nightseas 0:3dac4f477e98 123 {
nightseas 0:3dac4f477e98 124 switch(ch)
nightseas 0:3dac4f477e98 125 {
nightseas 0:3dac4f477e98 126 case 0:
nightseas 0:3dac4f477e98 127 if(led_mb)
nightseas 0:3dac4f477e98 128 led_mb = 0;
nightseas 0:3dac4f477e98 129 else
nightseas 0:3dac4f477e98 130 led_mb = 1;
nightseas 0:3dac4f477e98 131 break;
nightseas 0:3dac4f477e98 132
nightseas 0:3dac4f477e98 133 case 1:
nightseas 0:3dac4f477e98 134 if(led_db1_n)
nightseas 0:3dac4f477e98 135 led_db1_n = 0;
nightseas 0:3dac4f477e98 136 else
nightseas 0:3dac4f477e98 137 led_db1_n = 1;
nightseas 0:3dac4f477e98 138 break;
nightseas 0:3dac4f477e98 139
nightseas 0:3dac4f477e98 140 case 2:
nightseas 0:3dac4f477e98 141 if(led_db2_n)
nightseas 0:3dac4f477e98 142 led_db2_n = 0;
nightseas 0:3dac4f477e98 143 else
nightseas 0:3dac4f477e98 144 led_db2_n = 1;
nightseas 0:3dac4f477e98 145 break;
nightseas 0:3dac4f477e98 146
nightseas 0:3dac4f477e98 147 default:
nightseas 0:3dac4f477e98 148 break;
nightseas 0:3dac4f477e98 149 }
nightseas 0:3dac4f477e98 150 }
nightseas 0:3dac4f477e98 151
nightseas 0:3dac4f477e98 152 void LedOnAll(void)
nightseas 0:3dac4f477e98 153 {
nightseas 0:3dac4f477e98 154 for(int ledNum = 0; ledNum < LED_NUM_MAX; ledNum++)
nightseas 0:3dac4f477e98 155 LedOn(ledNum);
nightseas 0:3dac4f477e98 156 }
nightseas 0:3dac4f477e98 157
nightseas 0:3dac4f477e98 158 void LedOffAll(void)
nightseas 0:3dac4f477e98 159 {
nightseas 0:3dac4f477e98 160 for(int ledNum = 0; ledNum < LED_NUM_MAX; ledNum++)
nightseas 0:3dac4f477e98 161 LedOff(ledNum);
nightseas 0:3dac4f477e98 162 }