Browse Source

styling: convert TAB to four SPACES

Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
Kiveisha Yevgeniy 10 years ago
parent
commit
5b8922f7bf

+ 5
- 5
examples/4digitdisplay.cxx View File

29
 int
29
 int
30
 main(int argc, char **argv)
30
 main(int argc, char **argv)
31
 {
31
 {
32
-	uint8_t data[] = { 0xaa, 0xff, 0xff, 0xff };
32
+    uint8_t data[] = { 0xaa, 0xff, 0xff, 0xff };
33
 
33
 
34
     upm::TM1637 *display = new upm::TM1637(8, 9); // di - 8, dcki - 9
34
     upm::TM1637 *display = new upm::TM1637(8, 9); // di - 8, dcki - 9
35
-	display->write ("1981");
36
-	
37
-	std::cout << "exiting application" << std::endl;
35
+    display->write ("1981");
36
+    
37
+    std::cout << "exiting application" << std::endl;
38
 
38
 
39
-	delete display;
39
+    delete display;
40
 
40
 
41
     return 0;
41
     return 0;
42
 }
42
 }

+ 14
- 14
examples/buzzer-sound.cxx View File

33
 void
33
 void
34
 sig_handler(int signo)
34
 sig_handler(int signo)
35
 {
35
 {
36
-	printf("got signal\n");
36
+    printf("got signal\n");
37
     if (signo == SIGINT) {
37
     if (signo == SIGINT) {
38
         printf("exiting application\n");
38
         printf("exiting application\n");
39
         running = 1;
39
         running = 1;
42
 
42
 
43
 int
43
 int
44
 main(int argc, char **argv) {
44
 main(int argc, char **argv) {
45
-	int chord[] = { DO, RE, MI, FA, SOL, LA, SI, DO, SI };
46
-	// create Buzzer instance
45
+    int chord[] = { DO, RE, MI, FA, SOL, LA, SI, DO, SI };
46
+    // create Buzzer instance
47
     upm::Buzzer* sound = new upm::Buzzer(5);
47
     upm::Buzzer* sound = new upm::Buzzer(5);
48
-	// print sensor name
48
+    // print sensor name
49
     std::cout << sound->name() << std::endl;
49
     std::cout << sound->name() << std::endl;
50
-	// play sound (DO, RE, ME, etc...)
50
+    // play sound (DO, RE, ME, etc...)
51
 
51
 
52
-	signal(SIGINT, sig_handler);
52
+    signal(SIGINT, sig_handler);
53
 
53
 
54
-	while (!running) {
55
-		for (int chord_ind = 0; chord_ind < 9; chord_ind++) {
56
-			std::cout << sound->playSound(chord[chord_ind]) << std::endl;
57
-			usleep(1000);
58
-		}
59
-	}
54
+    while (!running) {
55
+        for (int chord_ind = 0; chord_ind < 9; chord_ind++) {
56
+            std::cout << sound->playSound(chord[chord_ind]) << std::endl;
57
+            usleep(1000);
58
+        }
59
+    }
60
 
60
 
61
-	std::cout << "exiting application" << std::endl;
61
+    std::cout << "exiting application" << std::endl;
62
 
62
 
63
-	delete sound;
63
+    delete sound;
64
     
64
     
65
     return 0;
65
     return 0;
66
 }
66
 }

+ 12
- 12
examples/led-bar.cxx View File

32
 void
32
 void
33
 sig_handler(int signo)
33
 sig_handler(int signo)
34
 {
34
 {
35
-	printf("got signal\n");
35
+    printf("got signal\n");
36
     if (signo == SIGINT) {
36
     if (signo == SIGINT) {
37
         printf("exiting application\n");
37
         printf("exiting application\n");
38
         running = 1;
38
         running = 1;
43
 main(int argc, char **argv)
43
 main(int argc, char **argv)
44
 {
44
 {
45
     upm::MY9221 *bar = new upm::MY9221(8, 9);
45
     upm::MY9221 *bar = new upm::MY9221(8, 9);
46
-	
47
-	signal(SIGINT, sig_handler);
48
-
49
-	while (!running) {
50
-		for (int idx = 1; idx < 11; idx++) {
51
-			bar->setBarLevel (idx);
52
-			usleep(1000);
53
-		}
54
-	}
46
+    
47
+    signal(SIGINT, sig_handler);
48
+
49
+    while (!running) {
50
+        for (int idx = 1; idx < 11; idx++) {
51
+            bar->setBarLevel (idx);
52
+            usleep(1000);
53
+        }
54
+    }
55
 
55
 
56
-	std::cout << "exiting application" << std::endl;
56
+    std::cout << "exiting application" << std::endl;
57
 
57
 
58
-	delete bar;
58
+    delete bar;
59
 
59
 
60
     return 0;
60
     return 0;
61
 }
61
 }

+ 14
- 14
examples/nrf_receiver.cxx View File

34
 void
34
 void
35
 sig_handler(int signo)
35
 sig_handler(int signo)
36
 {
36
 {
37
-	printf("got signal\n");
37
+    printf("got signal\n");
38
     if (signo == SIGINT) {
38
     if (signo == SIGINT) {
39
         printf("exiting application\n");
39
         printf("exiting application\n");
40
         running = 1;
40
         running = 1;
42
 }
42
 }
43
 
43
 
44
 void nrf_handler () {
44
 void nrf_handler () {
45
-	std::cout << "devi1 :: " << *((uint32_t *)&(comm->m_rxBuffer[0])) << std::endl;
45
+    std::cout << "devi1 :: " << *((uint32_t *)&(comm->m_rxBuffer[0])) << std::endl;
46
 }
46
 }
47
 
47
 
48
 int
48
 int
49
 main(int argc, char **argv)
49
 main(int argc, char **argv)
50
 {
50
 {
51
     comm = new upm::NRF24l01(7);
51
     comm = new upm::NRF24l01(7);
52
-	comm->nrfSetRXaddr ((uint8_t *) "devi1");
53
-	comm->nrfSetTXaddr ((uint8_t *) "devi2");
54
-	comm->nrfSetPayload (MAX_BUFFER);
55
-	comm->nrfConfigModule ();
56
-	comm->dataRecievedHandler = nrf_handler;
57
-	
58
-	signal(SIGINT, sig_handler);
52
+    comm->nrfSetRXaddr ((uint8_t *) "devi1");
53
+    comm->nrfSetTXaddr ((uint8_t *) "devi2");
54
+    comm->nrfSetPayload (MAX_BUFFER);
55
+    comm->nrfConfigModule ();
56
+    comm->dataRecievedHandler = nrf_handler;
57
+    
58
+    signal(SIGINT, sig_handler);
59
 
59
 
60
-	while (!running) {
61
-		comm->nrfListenForChannel ();
62
-	}
60
+    while (!running) {
61
+        comm->nrfListenForChannel ();
62
+    }
63
 
63
 
64
-	std::cout << "exiting application" << std::endl;
64
+    std::cout << "exiting application" << std::endl;
65
 
65
 
66
-	delete comm;
66
+    delete comm;
67
 
67
 
68
     return 0;
68
     return 0;
69
 }
69
 }

+ 18
- 18
examples/nrf_transmitter.cxx View File

34
 void
34
 void
35
 sig_handler(int signo)
35
 sig_handler(int signo)
36
 {
36
 {
37
-	printf("got signal\n");
37
+    printf("got signal\n");
38
     if (signo == SIGINT) {
38
     if (signo == SIGINT) {
39
         printf("exiting application\n");
39
         printf("exiting application\n");
40
         running = 1;
40
         running = 1;
47
 int
47
 int
48
 main(int argc, char **argv)
48
 main(int argc, char **argv)
49
 {
49
 {
50
-	uint32_t dummyData = 0;
50
+    uint32_t dummyData = 0;
51
     comm = new upm::NRF24l01(7);
51
     comm = new upm::NRF24l01(7);
52
-	comm->nrfSetRXaddr ((uint8_t *) "devi2");
53
-	comm->nrfSetTXaddr ((uint8_t *) "devi1");
54
-	comm->nrfSetPayload (MAX_BUFFER);
55
-	comm->nrfConfigModule ();
56
-	comm->dataRecievedHandler = nrf_handler;
57
-	
58
-	signal(SIGINT, sig_handler);
52
+    comm->nrfSetRXaddr ((uint8_t *) "devi2");
53
+    comm->nrfSetTXaddr ((uint8_t *) "devi1");
54
+    comm->nrfSetPayload (MAX_BUFFER);
55
+    comm->nrfConfigModule ();
56
+    comm->dataRecievedHandler = nrf_handler;
57
+    
58
+    signal(SIGINT, sig_handler);
59
 
59
 
60
-	while (!running) {
61
-		memcpy (comm->m_txBuffer, &dummyData, sizeof (dummyData));
62
-		comm->nrfSend ();
63
-		std::cout << "devi2 :: sending data ...." << dummyData << std::endl;
64
-		usleep (3000000);
65
-		dummyData += 3000;
66
-	}
60
+    while (!running) {
61
+        memcpy (comm->m_txBuffer, &dummyData, sizeof (dummyData));
62
+        comm->nrfSend ();
63
+        std::cout << "devi2 :: sending data ...." << dummyData << std::endl;
64
+        usleep (3000000);
65
+        dummyData += 3000;
66
+    }
67
 
67
 
68
-	std::cout << "exiting application" << std::endl;
68
+    std::cout << "exiting application" << std::endl;
69
 
69
 
70
-	delete comm;
70
+    delete comm;
71
 
71
 
72
     return 0;
72
     return 0;
73
 }
73
 }

+ 2
- 2
examples/rgb-lcd.cxx View File

27
 int
27
 int
28
 main(int argc, char **argv)
28
 main(int argc, char **argv)
29
 {
29
 {
30
-	// 0x62 RGB_ADDRESS, 0x3E LCD_ADDRESS
30
+    // 0x62 RGB_ADDRESS, 0x3E LCD_ADDRESS
31
     upm::Jhd1313m1 *lcd = new upm::Jhd1313m1(0, 0x3E, 0x62);
31
     upm::Jhd1313m1 *lcd = new upm::Jhd1313m1(0, 0x3E, 0x62);
32
-	lcd->setCursor(0,0);
32
+    lcd->setCursor(0,0);
33
     lcd->write("Hello World");
33
     lcd->write("Hello World");
34
     lcd->setCursor(1,2);
34
     lcd->setCursor(1,2);
35
     lcd->write("Hello World");
35
     lcd->write("Hello World");

+ 103
- 103
src/4digitdisplay/tm1637.cxx View File

31
 using namespace upm;
31
 using namespace upm;
32
 
32
 
33
 const uint8_t digitToSegment[] = {
33
 const uint8_t digitToSegment[] = {
34
- 	// XGFEDCBA
35
-	0b00111111,    // 0
36
-	0b00000110,    // 1
37
-	0b01011011,    // 2
38
-	0b01001111,    // 3
39
-	0b01100110,    // 4
40
-	0b01101101,    // 5
41
-	0b01111101,    // 6
42
-	0b00000111,    // 7
43
-	0b01111111,    // 8
44
-	0b01101111,    // 9
45
-	0b01110111,    // A
46
-	0b01111100,    // B
47
-	0b00111001,    // C
48
-	0b01000111,    // D
49
-	0b01111001,    // E
50
-	0b01110001     // F
34
+     // XGFEDCBA
35
+    0b00111111,    // 0
36
+    0b00000110,    // 1
37
+    0b01011011,    // 2
38
+    0b01001111,    // 3
39
+    0b01100110,    // 4
40
+    0b01101101,    // 5
41
+    0b01111101,    // 6
42
+    0b00000111,    // 7
43
+    0b01111111,    // 8
44
+    0b01101111,    // 9
45
+    0b01110111,    // A
46
+    0b01111100,    // B
47
+    0b00111001,    // C
48
+    0b01000111,    // D
49
+    0b01111001,    // E
50
+    0b01110001     // F
51
 };
51
 };
52
 
52
 
53
 TM1637::TM1637 (uint8_t di, uint8_t dcki) {
53
 TM1637::TM1637 (uint8_t di, uint8_t dcki) {
54
-	maa_result_t error = MAA_SUCCESS;
55
-	maa_init();
54
+    maa_result_t error = MAA_SUCCESS;
55
+    maa_init();
56
 
56
 
57
-	// init clock context
58
-	m_clkPinCtx = maa_gpio_init(dcki);
59
-	if (m_clkPinCtx == NULL) {
57
+    // init clock context
58
+    m_clkPinCtx = maa_gpio_init(dcki);
59
+    if (m_clkPinCtx == NULL) {
60
         fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", dcki);
60
         fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", dcki);
61
-		exit(1);
62
-	}
63
-	// init data context
64
-	m_dataPinCtx = maa_gpio_init(di);
65
-	if (m_dataPinCtx == NULL) {
61
+        exit(1);
62
+    }
63
+    // init data context
64
+    m_dataPinCtx = maa_gpio_init(di);
65
+    if (m_dataPinCtx == NULL) {
66
         fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", di);
66
         fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", di);
67
-		exit(1);
68
-	}
69
-	
70
-	// set direction (out)
71
-	error = maa_gpio_dir(m_clkPinCtx, MAA_GPIO_IN);
67
+        exit(1);
68
+    }
69
+    
70
+    // set direction (out)
71
+    error = maa_gpio_dir(m_clkPinCtx, MAA_GPIO_IN);
72
     if (error != MAA_SUCCESS) {
72
     if (error != MAA_SUCCESS) {
73
         maa_result_print(error);
73
         maa_result_print(error);
74
     }
74
     }
75
 
75
 
76
-	// set direction (out)
77
-	error = maa_gpio_dir(m_dataPinCtx, MAA_GPIO_IN);
76
+    // set direction (out)
77
+    error = maa_gpio_dir(m_dataPinCtx, MAA_GPIO_IN);
78
     if (error != MAA_SUCCESS) {
78
     if (error != MAA_SUCCESS) {
79
         maa_result_print(error);
79
         maa_result_print(error);
80
     }
80
     }
81
 
81
 
82
-	error = maa_gpio_write (m_dataPinCtx, LOW);
83
-	error = maa_gpio_write (m_clkPinCtx, LOW);
82
+    error = maa_gpio_write (m_dataPinCtx, LOW);
83
+    error = maa_gpio_write (m_clkPinCtx, LOW);
84
 }
84
 }
85
 
85
 
86
 TM1637::~TM1637() {
86
 TM1637::~TM1637() {
87
-	maa_result_t error = MAA_SUCCESS;
88
-	error = maa_gpio_close (m_dataPinCtx);
87
+    maa_result_t error = MAA_SUCCESS;
88
+    error = maa_gpio_close (m_dataPinCtx);
89
     if (error != MAA_SUCCESS) {
89
     if (error != MAA_SUCCESS) {
90
         maa_result_print(error);
90
         maa_result_print(error);
91
     }
91
     }
92
-	error = maa_gpio_close (m_clkPinCtx);
92
+    error = maa_gpio_close (m_clkPinCtx);
93
     if (error != MAA_SUCCESS) {
93
     if (error != MAA_SUCCESS) {
94
         maa_result_print(error);
94
         maa_result_print(error);
95
     }
95
     }
97
 
97
 
98
 maa_result_t
98
 maa_result_t
99
 TM1637::setBrightness (uint8_t level) {
99
 TM1637::setBrightness (uint8_t level) {
100
-	m_brightness = level;
100
+    m_brightness = level;
101
 }
101
 }
102
 
102
 
103
 maa_result_t
103
 maa_result_t
104
 TM1637::setSegments (const uint8_t segments[], uint8_t length, uint8_t pos) {
104
 TM1637::setSegments (const uint8_t segments[], uint8_t length, uint8_t pos) {
105
-	start();
106
-	writeByte(TM1637_I2C_COMM1);
107
-	stop();
108
-
109
-	start();
110
-	writeByte(TM1637_I2C_COMM2 + (pos & 0x03));
111
-	for (uint8_t idx = 0; idx < length; idx++) {
112
-		writeByte(segments[idx]);
113
-	}
114
-	stop();
115
-
116
-	start();
117
-	writeByte(TM1637_I2C_COMM3 + (m_brightness & 0x0f));
118
-	stop();
105
+    start();
106
+    writeByte(TM1637_I2C_COMM1);
107
+    stop();
108
+
109
+    start();
110
+    writeByte(TM1637_I2C_COMM2 + (pos & 0x03));
111
+    for (uint8_t idx = 0; idx < length; idx++) {
112
+        writeByte(segments[idx]);
113
+    }
114
+    stop();
115
+
116
+    start();
117
+    writeByte(TM1637_I2C_COMM3 + (m_brightness & 0x0f));
118
+    stop();
119
 }
119
 }
120
 
120
 
121
 maa_result_t
121
 maa_result_t
122
 TM1637::write (std::string msg) {
122
 TM1637::write (std::string msg) {
123
-	char leter = '\0';
124
-	uint8_t data[] = { 0x0, 0x0, 0x0, 0x0 };
125
-	for (uint8_t idx = 0; idx < msg.length(); idx++) {
126
-		leter = msg[idx];
127
-		if (idx < 4) {
128
-			data[idx] = digitToSegment[strtol(&leter, NULL, 16)];
129
-		}
130
-	}
131
-	setBrightness (0x0f);
132
-	setSegments(data);
123
+    char leter = '\0';
124
+    uint8_t data[] = { 0x0, 0x0, 0x0, 0x0 };
125
+    for (uint8_t idx = 0; idx < msg.length(); idx++) {
126
+        leter = msg[idx];
127
+        if (idx < 4) {
128
+            data[idx] = digitToSegment[strtol(&leter, NULL, 16)];
129
+        }
130
+    }
131
+    setBrightness (0x0f);
132
+    setSegments(data);
133
 }
133
 }
134
 
134
 
135
 maa_result_t
135
 maa_result_t
136
 TM1637::pinMode (maa_gpio_context ctx, gpio_dir_t mode) {
136
 TM1637::pinMode (maa_gpio_context ctx, gpio_dir_t mode) {
137
-	maa_result_t error = MAA_SUCCESS;
138
-	error = maa_gpio_dir(ctx, mode);
137
+    maa_result_t error = MAA_SUCCESS;
138
+    error = maa_gpio_dir(ctx, mode);
139
     if (error != MAA_SUCCESS) {
139
     if (error != MAA_SUCCESS) {
140
         maa_result_print(error);
140
         maa_result_print(error);
141
     }
141
     }
143
 
143
 
144
 maa_result_t
144
 maa_result_t
145
 TM1637::start() {
145
 TM1637::start() {
146
-	pinMode (m_dataPinCtx, MAA_GPIO_OUT);
147
-	usleep(PULSE_LENGTH);
146
+    pinMode (m_dataPinCtx, MAA_GPIO_OUT);
147
+    usleep(PULSE_LENGTH);
148
 }
148
 }
149
 
149
 
150
 maa_result_t
150
 maa_result_t
151
 TM1637::stop() {
151
 TM1637::stop() {
152
-	pinMode (m_dataPinCtx, MAA_GPIO_OUT);
153
-	usleep(PULSE_LENGTH);
154
-	pinMode (m_clkPinCtx, MAA_GPIO_IN);
155
-	usleep(PULSE_LENGTH);
156
-	pinMode (m_dataPinCtx, MAA_GPIO_IN);
157
-	usleep(PULSE_LENGTH);
152
+    pinMode (m_dataPinCtx, MAA_GPIO_OUT);
153
+    usleep(PULSE_LENGTH);
154
+    pinMode (m_clkPinCtx, MAA_GPIO_IN);
155
+    usleep(PULSE_LENGTH);
156
+    pinMode (m_dataPinCtx, MAA_GPIO_IN);
157
+    usleep(PULSE_LENGTH);
158
 }
158
 }
159
 
159
 
160
 maa_result_t
160
 maa_result_t
161
 TM1637::writeByte(uint8_t value) {
161
 TM1637::writeByte(uint8_t value) {
162
-	for (uint8_t idx = 0; idx < 8; idx++) {
163
-		pinMode(m_clkPinCtx, MAA_GPIO_OUT);
164
-		usleep(PULSE_LENGTH);
165
-		if (value & 0x01) {
166
-	  		pinMode(m_dataPinCtx, MAA_GPIO_IN);
167
-		} else {
168
-	  		pinMode(m_dataPinCtx, MAA_GPIO_OUT);
169
-		}
170
-		usleep(PULSE_LENGTH);
171
-
172
-		pinMode(m_clkPinCtx, MAA_GPIO_IN);
173
-		usleep(PULSE_LENGTH);
174
-		value = value >> 1;
175
-	}
176
-
177
-	pinMode(m_clkPinCtx, MAA_GPIO_OUT);
178
-	pinMode(m_dataPinCtx, MAA_GPIO_IN);
179
-	usleep(PULSE_LENGTH);
180
-
181
-	pinMode(m_clkPinCtx, MAA_GPIO_IN);
182
-	usleep(PULSE_LENGTH);
183
-
184
-	uint8_t ack = maa_gpio_read (m_dataPinCtx);
185
-	if (ack == 0) {
186
-    	pinMode(m_dataPinCtx, MAA_GPIO_OUT);
187
-	} usleep(PULSE_LENGTH);
188
-
189
-	pinMode(m_clkPinCtx, MAA_GPIO_OUT);
190
-	usleep(50);
162
+    for (uint8_t idx = 0; idx < 8; idx++) {
163
+        pinMode(m_clkPinCtx, MAA_GPIO_OUT);
164
+        usleep(PULSE_LENGTH);
165
+        if (value & 0x01) {
166
+              pinMode(m_dataPinCtx, MAA_GPIO_IN);
167
+        } else {
168
+              pinMode(m_dataPinCtx, MAA_GPIO_OUT);
169
+        }
170
+        usleep(PULSE_LENGTH);
171
+
172
+        pinMode(m_clkPinCtx, MAA_GPIO_IN);
173
+        usleep(PULSE_LENGTH);
174
+        value = value >> 1;
175
+    }
176
+
177
+    pinMode(m_clkPinCtx, MAA_GPIO_OUT);
178
+    pinMode(m_dataPinCtx, MAA_GPIO_IN);
179
+    usleep(PULSE_LENGTH);
180
+
181
+    pinMode(m_clkPinCtx, MAA_GPIO_IN);
182
+    usleep(PULSE_LENGTH);
183
+
184
+    uint8_t ack = maa_gpio_read (m_dataPinCtx);
185
+    if (ack == 0) {
186
+        pinMode(m_dataPinCtx, MAA_GPIO_OUT);
187
+    } usleep(PULSE_LENGTH);
188
+
189
+    pinMode(m_clkPinCtx, MAA_GPIO_OUT);
190
+    usleep(50);
191
 }
191
 }

+ 26
- 26
src/4digitdisplay/tm1637.h View File

36
 //     ---
36
 //     ---
37
 //      D
37
 //      D
38
 
38
 
39
-#define SEG_A   			0b00000001
40
-#define SEG_B   			0b00000010
41
-#define SEG_C   			0b00000100
42
-#define SEG_D   			0b00001000
43
-#define SEG_E   			0b00010000
44
-#define SEG_F   			0b00100000
45
-#define SEG_G   			0b01000000
39
+#define SEG_A               0b00000001
40
+#define SEG_B               0b00000010
41
+#define SEG_C               0b00000100
42
+#define SEG_D               0b00001000
43
+#define SEG_E               0b00010000
44
+#define SEG_F               0b00100000
45
+#define SEG_G               0b01000000
46
 
46
 
47
 #define TM1637_I2C_COMM1    0x40
47
 #define TM1637_I2C_COMM1    0x40
48
 #define TM1637_I2C_COMM2    0xC0
48
 #define TM1637_I2C_COMM2    0xC0
49
 #define TM1637_I2C_COMM3    0x80
49
 #define TM1637_I2C_COMM3    0x80
50
 
50
 
51
-#define PULSE_LENGTH		50
51
+#define PULSE_LENGTH        50
52
 
52
 
53
-#define HIGH          		1
54
-#define LOW	        		0
53
+#define HIGH                  1
54
+#define LOW                    0
55
 
55
 
56
 namespace upm {
56
 namespace upm {
57
 
57
 
58
 class TM1637 {
58
 class TM1637 {
59
     public:
59
     public:
60
-		TM1637 (uint8_t di, uint8_t dcki);
61
-		~TM1637 ();
62
-		maa_result_t setBrightness (uint8_t level);
63
-		maa_result_t setSegments (const uint8_t segments[], uint8_t length = 4, uint8_t pos = 0);
64
-		maa_result_t write (std::string msg);
65
-		
66
-		std::string name()
60
+        TM1637 (uint8_t di, uint8_t dcki);
61
+        ~TM1637 ();
62
+        maa_result_t setBrightness (uint8_t level);
63
+        maa_result_t setSegments (const uint8_t segments[], uint8_t length = 4, uint8_t pos = 0);
64
+        maa_result_t write (std::string msg);
65
+        
66
+        std::string name()
67
         {
67
         {
68
             return m_name;
68
             return m_name;
69
         }
69
         }
70
-	private:
71
-		maa_result_t start();
72
-		maa_result_t stop();
73
-		maa_result_t writeByte (uint8_t value);
74
-		maa_result_t pinMode (maa_gpio_context ctx, gpio_dir_t mode);
70
+    private:
71
+        maa_result_t start();
72
+        maa_result_t stop();
73
+        maa_result_t writeByte (uint8_t value);
74
+        maa_result_t pinMode (maa_gpio_context ctx, gpio_dir_t mode);
75
 
75
 
76
-		std::string m_name;
77
-		maa_gpio_context m_clkPinCtx;
78
-		maa_gpio_context m_dataPinCtx;
79
-		uint8_t m_brightness;
76
+        std::string m_name;
77
+        maa_gpio_context m_clkPinCtx;
78
+        maa_gpio_context m_dataPinCtx;
79
+        uint8_t m_brightness;
80
 };
80
 };
81
 
81
 
82
 }
82
 }

+ 10
- 10
src/buzzer/buzzer.cxx View File

30
 using namespace upm;
30
 using namespace upm;
31
 
31
 
32
 Buzzer::Buzzer (int pinNumber) {
32
 Buzzer::Buzzer (int pinNumber) {
33
-	m_pwm_context = maa_pwm_init (pinNumber);
34
-	m_name = "Buzzer";
33
+    m_pwm_context = maa_pwm_init (pinNumber);
34
+    m_name = "Buzzer";
35
 }
35
 }
36
 
36
 
37
 int Buzzer::playSound (int note) {
37
 int Buzzer::playSound (int note) {
38
-	maa_pwm_enable (m_pwm_context, 1);
39
-	maa_pwm_period_us (m_pwm_context, note);
40
-	maa_pwm_write (m_pwm_context, 50.0);
41
-	usleep (10000);
42
-	maa_pwm_enable (m_pwm_context, 0);
38
+    maa_pwm_enable (m_pwm_context, 1);
39
+    maa_pwm_period_us (m_pwm_context, note);
40
+    maa_pwm_write (m_pwm_context, 50.0);
41
+    usleep (10000);
42
+    maa_pwm_enable (m_pwm_context, 0);
43
 
43
 
44
-	return 0;
44
+    return 0;
45
 }
45
 }
46
 
46
 
47
 Buzzer::~Buzzer() {
47
 Buzzer::~Buzzer() {
48
-	maa_pwm_close(m_pwm_context);
49
-	std::cout << "executed maa_pwm_close" << std::endl;
48
+    maa_pwm_close(m_pwm_context);
49
+    std::cout << "executed maa_pwm_close" << std::endl;
50
 }
50
 }
51
 
51
 

+ 5
- 5
src/buzzer/buzzer.h View File

38
 
38
 
39
 class Buzzer {
39
 class Buzzer {
40
     public:
40
     public:
41
-		Buzzer (int pinNumber);
42
-		~Buzzer ();
43
-		int playSound (int note);
41
+        Buzzer (int pinNumber);
42
+        ~Buzzer ();
43
+        int playSound (int note);
44
         std::string name()
44
         std::string name()
45
         {
45
         {
46
             return m_name;
46
             return m_name;
47
         }
47
         }
48
     protected:
48
     protected:
49
         std::string m_name;
49
         std::string m_name;
50
-	private:
51
-		maa_pwm_context m_pwm_context;
50
+    private:
51
+        maa_pwm_context m_pwm_context;
52
 };
52
 };
53
 }
53
 }

+ 5
- 5
src/lcd/iiclcd.cxx View File

30
 using namespace upm;
30
 using namespace upm;
31
 
31
 
32
 IICLcd::IICLcd (int bus, int lcdAddress) {
32
 IICLcd::IICLcd (int bus, int lcdAddress) {
33
-	m_lcd_control_address = lcdAddress;
33
+    m_lcd_control_address = lcdAddress;
34
     m_bus = bus;
34
     m_bus = bus;
35
 
35
 
36
     m_i2c_lcd_control = maa_i2c_init(m_bus);
36
     m_i2c_lcd_control = maa_i2c_init(m_bus);
37
 
37
 
38
     maa_result_t ret = maa_i2c_address(m_i2c_lcd_control, m_lcd_control_address);
38
     maa_result_t ret = maa_i2c_address(m_i2c_lcd_control, m_lcd_control_address);
39
-	if (ret != MAA_SUCCESS) {
39
+    if (ret != MAA_SUCCESS) {
40
         fprintf(stderr, "Messed up i2c bus\n");
40
         fprintf(stderr, "Messed up i2c bus\n");
41
     }
41
     }
42
 }
42
 }
43
 
43
 
44
 maa_result_t
44
 maa_result_t
45
 IICLcd::write (int row, int column, std::string msg) {
45
 IICLcd::write (int row, int column, std::string msg) {
46
-	setCursor (row, column);
47
-	write (msg);
46
+    setCursor (row, column);
47
+    write (msg);
48
 }
48
 }
49
 
49
 
50
 maa_result_t
50
 maa_result_t
51
 IICLcd::close() {
51
 IICLcd::close() {
52
-	return maa_i2c_stop(m_i2c_lcd_control);
52
+    return maa_i2c_stop(m_i2c_lcd_control);
53
 }
53
 }

+ 14
- 14
src/lcd/iiclcd.h View File

68
 #define LCD_RS 0x01 // Register select bit
68
 #define LCD_RS 0x01 // Register select bit
69
 
69
 
70
 class IICLcd {
70
 class IICLcd {
71
-	public:
72
-		IICLcd (int bus, int lcdAddress);
73
-		virtual maa_result_t write (std::string msg) = 0;
74
-		maa_result_t write (int x, int y, std::string msg);
75
-		virtual maa_result_t setCursor (int row, int column) = 0;
76
-		virtual maa_result_t clear () = 0;
77
-		virtual maa_result_t home () = 0;
78
-		maa_result_t close();
79
-		std::string name()
71
+    public:
72
+        IICLcd (int bus, int lcdAddress);
73
+        virtual maa_result_t write (std::string msg) = 0;
74
+        maa_result_t write (int x, int y, std::string msg);
75
+        virtual maa_result_t setCursor (int row, int column) = 0;
76
+        virtual maa_result_t clear () = 0;
77
+        virtual maa_result_t home () = 0;
78
+        maa_result_t close();
79
+        std::string name()
80
         {
80
         {
81
             return m_name;
81
             return m_name;
82
         }
82
         }
83
-	protected:
84
-		std::string m_name;
85
-		int m_lcd_control_address;
86
-	    int m_bus;
87
-		maa_i2c_context m_i2c_lcd_control;
83
+    protected:
84
+        std::string m_name;
85
+        int m_lcd_control_address;
86
+        int m_bus;
87
+        maa_i2c_context m_i2c_lcd_control;
88
 };
88
 };
89
 
89
 
90
 }
90
 }

+ 53
- 53
src/lcd/jhd1313m1.cxx View File

30
 using namespace upm;
30
 using namespace upm;
31
 
31
 
32
 Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : IICLcd(bus, lcdAddress) {
32
 Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : IICLcd(bus, lcdAddress) {
33
-	maa_result_t error = MAA_SUCCESS;
33
+    maa_result_t error = MAA_SUCCESS;
34
 
34
 
35
-	m_rgb_address = rgbAddress;
36
-	m_i2c_lcd_rgb = maa_i2c_init(m_bus);
35
+    m_rgb_address = rgbAddress;
36
+    m_i2c_lcd_rgb = maa_i2c_init(m_bus);
37
 
37
 
38
-	maa_result_t ret = maa_i2c_address(m_i2c_lcd_rgb, m_rgb_address);
39
-	if (ret != MAA_SUCCESS) {
38
+    maa_result_t ret = maa_i2c_address(m_i2c_lcd_rgb, m_rgb_address);
39
+    if (ret != MAA_SUCCESS) {
40
         fprintf(stderr, "Messed up i2c bus\n");
40
         fprintf(stderr, "Messed up i2c bus\n");
41
     }
41
     }
42
 
42
 
43
-	usleep(50000);
43
+    usleep(50000);
44
     cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
44
     cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
45
-	usleep(4500);
46
-	cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
47
-	usleep(4500);
48
-	cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
49
-	usleep(4500);
50
-	cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
51
-
52
-	cmd (m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON);
53
-	clear ();
54
-	usleep(4500);
55
-	
56
-    cmd (m_i2c_lcd_control, 	LCD_ENTRYMODESET |
57
-							LCD_ENTRYLEFT |
58
-							LCD_ENTRYSHIFTDECREMENT);
59
-
60
-	setReg (m_i2c_lcd_rgb, m_rgb_address, 0, 0);
61
-	setReg (m_i2c_lcd_rgb, m_rgb_address, 1, 0);
62
-	setReg (m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA);
63
-
64
-	setReg (m_i2c_lcd_rgb, m_rgb_address, 0x04, 255);
45
+    usleep(4500);
46
+    cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
47
+    usleep(4500);
48
+    cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
49
+    usleep(4500);
50
+    cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
51
+
52
+    cmd (m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON);
53
+    clear ();
54
+    usleep(4500);
55
+    
56
+    cmd (m_i2c_lcd_control,     LCD_ENTRYMODESET |
57
+                            LCD_ENTRYLEFT |
58
+                            LCD_ENTRYSHIFTDECREMENT);
59
+
60
+    setReg (m_i2c_lcd_rgb, m_rgb_address, 0, 0);
61
+    setReg (m_i2c_lcd_rgb, m_rgb_address, 1, 0);
62
+    setReg (m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA);
63
+
64
+    setReg (m_i2c_lcd_rgb, m_rgb_address, 0x04, 255);
65
     setReg (m_i2c_lcd_rgb, m_rgb_address, 0x03, 255);
65
     setReg (m_i2c_lcd_rgb, m_rgb_address, 0x03, 255);
66
     setReg (m_i2c_lcd_rgb, m_rgb_address, 0x02, 255);
66
     setReg (m_i2c_lcd_rgb, m_rgb_address, 0x02, 255);
67
 }
67
 }
68
 
68
 
69
 Jhd1313m1::~Jhd1313m1() {
69
 Jhd1313m1::~Jhd1313m1() {
70
-	
70
+    
71
 }
71
 }
72
 
72
 
73
 /*
73
 /*
77
  */
77
  */
78
 maa_result_t
78
 maa_result_t
79
 Jhd1313m1::write (std::string msg) {
79
 Jhd1313m1::write (std::string msg) {
80
-	maa_result_t error = MAA_SUCCESS;
81
-	uint8_t data[2] = {0x40, 0};
82
-	for (std::string::size_type i = 0; i < msg.size(); ++i) {
83
-		data[1] = msg[i];
84
-		error = maa_i2c_address (m_i2c_lcd_control, m_lcd_control_address);
85
-		error = maa_i2c_write (m_i2c_lcd_control, data, 2);
80
+    maa_result_t error = MAA_SUCCESS;
81
+    uint8_t data[2] = {0x40, 0};
82
+    for (std::string::size_type i = 0; i < msg.size(); ++i) {
83
+        data[1] = msg[i];
84
+        error = maa_i2c_address (m_i2c_lcd_control, m_lcd_control_address);
85
+        error = maa_i2c_write (m_i2c_lcd_control, data, 2);
86
     }
86
     }
87
 
87
 
88
-	return error;
88
+    return error;
89
 }
89
 }
90
 
90
 
91
 maa_result_t
91
 maa_result_t
92
 Jhd1313m1::setCursor (int row, int column) {
92
 Jhd1313m1::setCursor (int row, int column) {
93
-	maa_result_t error = MAA_SUCCESS;
93
+    maa_result_t error = MAA_SUCCESS;
94
 
94
 
95
-	int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
96
-	uint8_t offset = ((column % 16) + row_addr[row]);
95
+    int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
96
+    uint8_t offset = ((column % 16) + row_addr[row]);
97
 
97
 
98
-	uint8_t data[2] = { 0x80, offset };
99
-	error = maa_i2c_address (m_i2c_lcd_control, m_lcd_control_address);
100
-	error = maa_i2c_write (m_i2c_lcd_control, data, 2);
98
+    uint8_t data[2] = { 0x80, offset };
99
+    error = maa_i2c_address (m_i2c_lcd_control, m_lcd_control_address);
100
+    error = maa_i2c_write (m_i2c_lcd_control, data, 2);
101
 
101
 
102
-	return error;
102
+    return error;
103
 }
103
 }
104
 
104
 
105
 maa_result_t
105
 maa_result_t
106
 Jhd1313m1::clear () {
106
 Jhd1313m1::clear () {
107
-	return cmd (m_i2c_lcd_control, LCD_CLEARDISPLAY);
107
+    return cmd (m_i2c_lcd_control, LCD_CLEARDISPLAY);
108
 }
108
 }
109
 
109
 
110
 maa_result_t
110
 maa_result_t
111
 Jhd1313m1::home () {
111
 Jhd1313m1::home () {
112
-	return cmd (m_i2c_lcd_control, LCD_RETURNHOME);
112
+    return cmd (m_i2c_lcd_control, LCD_RETURNHOME);
113
 }
113
 }
114
 
114
 
115
 /*
115
 /*
119
  */
119
  */
120
 maa_result_t
120
 maa_result_t
121
 Jhd1313m1::setReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
121
 Jhd1313m1::setReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
122
-	maa_result_t error = MAA_SUCCESS;
122
+    maa_result_t error = MAA_SUCCESS;
123
 
123
 
124
-	uint8_t data[2] = { addr, value };
125
-	error = maa_i2c_address (ctx, deviceAdress);
126
-	error = maa_i2c_write (ctx, data, 2);
124
+    uint8_t data[2] = { addr, value };
125
+    error = maa_i2c_address (ctx, deviceAdress);
126
+    error = maa_i2c_write (ctx, data, 2);
127
 
127
 
128
-	return error;
128
+    return error;
129
 }
129
 }
130
 
130
 
131
 maa_result_t
131
 maa_result_t
132
 Jhd1313m1::cmd (maa_i2c_context ctx, uint8_t value) {
132
 Jhd1313m1::cmd (maa_i2c_context ctx, uint8_t value) {
133
-	maa_result_t error = MAA_SUCCESS;
133
+    maa_result_t error = MAA_SUCCESS;
134
 
134
 
135
-	uint8_t data[2] = { 0x80, value };
136
-	error = maa_i2c_address (ctx, m_lcd_control_address);
137
-	error = maa_i2c_write (ctx, data, 2);
135
+    uint8_t data[2] = { 0x80, value };
136
+    error = maa_i2c_address (ctx, m_lcd_control_address);
137
+    error = maa_i2c_write (ctx, data, 2);
138
 
138
 
139
-	return error;
139
+    return error;
140
 }
140
 }

+ 11
- 11
src/lcd/jhd1313m1.h View File

30
 
30
 
31
 class Jhd1313m1 : public IICLcd {
31
 class Jhd1313m1 : public IICLcd {
32
     public:
32
     public:
33
-		Jhd1313m1 (int bus, int lcdAddress, int rgbAddress);
34
-		~Jhd1313m1 ();
35
-		maa_result_t write (std::string msg);
36
-		maa_result_t setCursor (int row, int column);
37
-		maa_result_t clear ();
38
-		maa_result_t home ();
33
+        Jhd1313m1 (int bus, int lcdAddress, int rgbAddress);
34
+        ~Jhd1313m1 ();
35
+        maa_result_t write (std::string msg);
36
+        maa_result_t setCursor (int row, int column);
37
+        maa_result_t clear ();
38
+        maa_result_t home ();
39
 
39
 
40
-	private:
41
-		maa_result_t cmd (maa_i2c_context ctx, uint8_t value);
42
-		maa_result_t setReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
40
+    private:
41
+        maa_result_t cmd (maa_i2c_context ctx, uint8_t value);
42
+        maa_result_t setReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
43
 
43
 
44
-		int m_rgb_address;
45
-		maa_i2c_context m_i2c_lcd_rgb;
44
+        int m_rgb_address;
45
+        maa_i2c_context m_i2c_lcd_rgb;
46
 };
46
 };
47
 
47
 
48
 }
48
 }

+ 12
- 12
src/lcd/lcm1602.cxx View File

33
 using namespace upm;
33
 using namespace upm;
34
 
34
 
35
 Lcm1602::Lcm1602(int bus_in, int addr_in) : IICLcd (bus_in, addr_in) {
35
 Lcm1602::Lcm1602(int bus_in, int addr_in) : IICLcd (bus_in, addr_in) {
36
-	maa_result_t error = MAA_SUCCESS;
36
+    maa_result_t error = MAA_SUCCESS;
37
 
37
 
38
-	usleep(50000);
39
-	expandWrite(LCD_BACKLIGHT);
38
+    usleep(50000);
39
+    expandWrite(LCD_BACKLIGHT);
40
     usleep(100000);
40
     usleep(100000);
41
 
41
 
42
     write4bits(0x03 << 4);
42
     write4bits(0x03 << 4);
61
 }
61
 }
62
 
62
 
63
 Lcm1602::~Lcm1602 () {
63
 Lcm1602::~Lcm1602 () {
64
-	
64
+    
65
 }
65
 }
66
 
66
 
67
 /*
67
 /*
71
  */
71
  */
72
 maa_result_t
72
 maa_result_t
73
 Lcm1602::write (std::string msg) {
73
 Lcm1602::write (std::string msg) {
74
-	maa_result_t error = MAA_SUCCESS;
74
+    maa_result_t error = MAA_SUCCESS;
75
     for (std::string::size_type i = 0; i < msg.size(); ++i) {
75
     for (std::string::size_type i = 0; i < msg.size(); ++i) {
76
         error = send (msg[i], LCD_RS);
76
         error = send (msg[i], LCD_RS);
77
     }
77
     }
80
 
80
 
81
 maa_result_t
81
 maa_result_t
82
 Lcm1602::setCursor (int row, int column) {
82
 Lcm1602::setCursor (int row, int column) {
83
-	maa_result_t error = MAA_SUCCESS;
83
+    maa_result_t error = MAA_SUCCESS;
84
 
84
 
85
-	int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
86
-	uint8_t offset = ((column % 16) + row_addr[row]);
85
+    int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
86
+    uint8_t offset = ((column % 16) + row_addr[row]);
87
 
87
 
88
-	return send (LCD_SETDDRAMADDR | offset, 0);
88
+    return send (LCD_SETDDRAMADDR | offset, 0);
89
 }
89
 }
90
 
90
 
91
 maa_result_t
91
 maa_result_t
92
 Lcm1602::clear () {
92
 Lcm1602::clear () {
93
-	return send(LCD_CLEARDISPLAY, 0);
93
+    return send(LCD_CLEARDISPLAY, 0);
94
 }
94
 }
95
 
95
 
96
 maa_result_t
96
 maa_result_t
97
 Lcm1602::home () {
97
 Lcm1602::home () {
98
-	return send(LCD_RETURNHOME, 0);
98
+    return send(LCD_RETURNHOME, 0);
99
 }
99
 }
100
 
100
 
101
 /*
101
 /*
105
  */
105
  */
106
 maa_result_t
106
 maa_result_t
107
 Lcm1602::send (uint8_t value, int mode) {
107
 Lcm1602::send (uint8_t value, int mode) {
108
-	maa_result_t ret = MAA_SUCCESS;
108
+    maa_result_t ret = MAA_SUCCESS;
109
     uint8_t h = value & 0xf0;
109
     uint8_t h = value & 0xf0;
110
     uint8_t l = (value << 4) & 0xf0;
110
     uint8_t l = (value << 4) & 0xf0;
111
     ret = write4bits(h | mode);
111
     ret = write4bits(h | mode);

+ 18
- 18
src/lcd/lcm1602.h View File

33
 namespace upm {
33
 namespace upm {
34
 
34
 
35
 class Lcm1602 : public IICLcd {
35
 class Lcm1602 : public IICLcd {
36
-	public:
37
-		/** LCM1602 Constructor.
38
-		 * Calls MAA initialisation functions.
39
-		 * @param bus i2c bus to use
40
-		 * @param address the slave address the lcd is registered on.
41
-		 */
42
-		Lcm1602(int bus, int address);
43
-		~Lcm1602();
44
-		maa_result_t write (std::string msg);
45
-		maa_result_t setCursor (int row, int column);
46
-		maa_result_t clear ();
47
-		maa_result_t home ();
36
+    public:
37
+        /** LCM1602 Constructor.
38
+         * Calls MAA initialisation functions.
39
+         * @param bus i2c bus to use
40
+         * @param address the slave address the lcd is registered on.
41
+         */
42
+        Lcm1602(int bus, int address);
43
+        ~Lcm1602();
44
+        maa_result_t write (std::string msg);
45
+        maa_result_t setCursor (int row, int column);
46
+        maa_result_t clear ();
47
+        maa_result_t home ();
48
 
48
 
49
-	private :
50
-		maa_result_t send (uint8_t value, int mode);
51
-		maa_result_t write4bits(uint8_t value);
52
-		maa_result_t expandWrite(uint8_t value);
53
-		maa_result_t pulseEnable(uint8_t value);
54
-	};
49
+    private :
50
+        maa_result_t send (uint8_t value, int mode);
51
+        maa_result_t write4bits(uint8_t value);
52
+        maa_result_t expandWrite(uint8_t value);
53
+        maa_result_t pulseEnable(uint8_t value);
54
+    };
55
 }
55
 }

+ 45
- 45
src/ledbar/my9221.cxx View File

31
 using namespace upm;
31
 using namespace upm;
32
 
32
 
33
 MY9221::MY9221 (uint8_t di, uint8_t dcki) {
33
 MY9221::MY9221 (uint8_t di, uint8_t dcki) {
34
-	maa_result_t error = MAA_SUCCESS;
35
-	maa_init();
34
+    maa_result_t error = MAA_SUCCESS;
35
+    maa_init();
36
 
36
 
37
-	// init clock context
38
-	m_clkPinCtx = maa_gpio_init(dcki);
39
-	if (m_clkPinCtx == NULL) {
37
+    // init clock context
38
+    m_clkPinCtx = maa_gpio_init(dcki);
39
+    if (m_clkPinCtx == NULL) {
40
         fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", dcki);
40
         fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", dcki);
41
-		exit(1);
42
-	}
43
-	// init data context
44
-	m_dataPinCtx = maa_gpio_init(di);
45
-	if (m_dataPinCtx == NULL) {
41
+        exit(1);
42
+    }
43
+    // init data context
44
+    m_dataPinCtx = maa_gpio_init(di);
45
+    if (m_dataPinCtx == NULL) {
46
         fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", di);
46
         fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", di);
47
-		exit(1);
48
-	}
49
-	
50
-	// set direction (out)
51
-	error = maa_gpio_dir(m_clkPinCtx, MAA_GPIO_OUT);
47
+        exit(1);
48
+    }
49
+    
50
+    // set direction (out)
51
+    error = maa_gpio_dir(m_clkPinCtx, MAA_GPIO_OUT);
52
     if (error != MAA_SUCCESS) {
52
     if (error != MAA_SUCCESS) {
53
         maa_result_print(error);
53
         maa_result_print(error);
54
     }
54
     }
55
 
55
 
56
-	// set direction (out)
57
-	error = maa_gpio_dir(m_dataPinCtx, MAA_GPIO_OUT);
56
+    // set direction (out)
57
+    error = maa_gpio_dir(m_dataPinCtx, MAA_GPIO_OUT);
58
     if (error != MAA_SUCCESS) {
58
     if (error != MAA_SUCCESS) {
59
         maa_result_print(error);
59
         maa_result_print(error);
60
     }
60
     }
61
 }
61
 }
62
 
62
 
63
 MY9221::~MY9221() {
63
 MY9221::~MY9221() {
64
-	maa_result_t error = MAA_SUCCESS;
65
-	error = maa_gpio_close (m_dataPinCtx);
64
+    maa_result_t error = MAA_SUCCESS;
65
+    error = maa_gpio_close (m_dataPinCtx);
66
     if (error != MAA_SUCCESS) {
66
     if (error != MAA_SUCCESS) {
67
         maa_result_print(error);
67
         maa_result_print(error);
68
     }
68
     }
69
-	error = maa_gpio_close (m_clkPinCtx);
69
+    error = maa_gpio_close (m_clkPinCtx);
70
     if (error != MAA_SUCCESS) {
70
     if (error != MAA_SUCCESS) {
71
         maa_result_print(error);
71
         maa_result_print(error);
72
     }
72
     }
74
 
74
 
75
 maa_result_t
75
 maa_result_t
76
 MY9221::setBarLevel (uint8_t level) {
76
 MY9221::setBarLevel (uint8_t level) {
77
-	if (level > 10) {
78
-		return MAA_ERROR_INVALID_PARAMETER;
79
-	}
77
+    if (level > 10) {
78
+        return MAA_ERROR_INVALID_PARAMETER;
79
+    }
80
 
80
 
81
-	send16bitBlock (CMDMODE);
82
-	for(uint8_t block_idx = 0; block_idx < 12; block_idx++) {
81
+    send16bitBlock (CMDMODE);
82
+    for(uint8_t block_idx = 0; block_idx < 12; block_idx++) {
83
         uint32_t state = (block_idx < level) ? BIT_HIGH : BIT_LOW;
83
         uint32_t state = (block_idx < level) ? BIT_HIGH : BIT_LOW;
84
         send16bitBlock (state);
84
         send16bitBlock (state);
85
     }
85
     }
88
 
88
 
89
 maa_result_t
89
 maa_result_t
90
 MY9221::lockData () {
90
 MY9221::lockData () {
91
-	maa_result_t error = MAA_SUCCESS;
92
-	error = maa_gpio_write (m_dataPinCtx, LOW);
93
-	usleep(100);
94
-	
95
-	for(int idx = 0; idx < 4; idx++) {
96
-		error = maa_gpio_write (m_dataPinCtx, HIGH);
97
-		error = maa_gpio_write (m_dataPinCtx, LOW);
91
+    maa_result_t error = MAA_SUCCESS;
92
+    error = maa_gpio_write (m_dataPinCtx, LOW);
93
+    usleep(100);
94
+    
95
+    for(int idx = 0; idx < 4; idx++) {
96
+        error = maa_gpio_write (m_dataPinCtx, HIGH);
97
+        error = maa_gpio_write (m_dataPinCtx, LOW);
98
     }
98
     }
99
 }
99
 }
100
 
100
 
101
 maa_result_t
101
 maa_result_t
102
 MY9221::send16bitBlock (short data) {
102
 MY9221::send16bitBlock (short data) {
103
-	maa_result_t error = MAA_SUCCESS;
104
-	for (uint8_t bit_idx = 0; bit_idx < MAX_BIT_PER_BLOCK; bit_idx++) {
105
-		uint32_t state = (data & 0x8000) ? HIGH : LOW;
106
-		error = maa_gpio_write (m_dataPinCtx, state);
107
-		state = maa_gpio_read (m_clkPinCtx);
103
+    maa_result_t error = MAA_SUCCESS;
104
+    for (uint8_t bit_idx = 0; bit_idx < MAX_BIT_PER_BLOCK; bit_idx++) {
105
+        uint32_t state = (data & 0x8000) ? HIGH : LOW;
106
+        error = maa_gpio_write (m_dataPinCtx, state);
107
+        state = maa_gpio_read (m_clkPinCtx);
108
 
108
 
109
-		if (state) {
110
-			state = LOW;
111
-		} else {
112
-			state = HIGH;
113
-		}
109
+        if (state) {
110
+            state = LOW;
111
+        } else {
112
+            state = HIGH;
113
+        }
114
 
114
 
115
-		error = maa_gpio_write (m_clkPinCtx, state);
115
+        error = maa_gpio_write (m_clkPinCtx, state);
116
 
116
 
117
-		data <<= 1;
118
-	}
117
+        data <<= 1;
118
+    }
119
 }
119
 }

+ 16
- 16
src/ledbar/my9221.h View File

27
 #include <maa/aio.h>
27
 #include <maa/aio.h>
28
 #include <maa/gpio.h>
28
 #include <maa/gpio.h>
29
 
29
 
30
-#define MAX_BIT_PER_BLOCK 	16
31
-#define CMDMODE     		0x0000
32
-#define BIT_HIGH          	0x00ff
33
-#define BIT_LOW	        	0x0000
30
+#define MAX_BIT_PER_BLOCK     16
31
+#define CMDMODE             0x0000
32
+#define BIT_HIGH              0x00ff
33
+#define BIT_LOW                0x0000
34
 
34
 
35
-#define HIGH          		1
36
-#define LOW	        		0
35
+#define HIGH                  1
36
+#define LOW                    0
37
 
37
 
38
 namespace upm {
38
 namespace upm {
39
 
39
 
40
 class MY9221 {
40
 class MY9221 {
41
     public:
41
     public:
42
-		MY9221 (uint8_t di, uint8_t dcki);
43
-		~MY9221 ();
44
-		maa_result_t setBarLevel (uint8_t level);
45
-		std::string name()
42
+        MY9221 (uint8_t di, uint8_t dcki);
43
+        ~MY9221 ();
44
+        maa_result_t setBarLevel (uint8_t level);
45
+        std::string name()
46
         {
46
         {
47
             return m_name;
47
             return m_name;
48
         }
48
         }
49
-	private:
50
-		maa_result_t lockData ();
51
-		maa_result_t send16bitBlock (short data);
49
+    private:
50
+        maa_result_t lockData ();
51
+        maa_result_t send16bitBlock (short data);
52
 
52
 
53
-		std::string m_name;
54
-		maa_gpio_context m_clkPinCtx;
55
-		maa_gpio_context m_dataPinCtx;
53
+        std::string m_name;
54
+        maa_gpio_context m_clkPinCtx;
55
+        maa_gpio_context m_dataPinCtx;
56
 };
56
 };
57
 
57
 
58
 }
58
 }

+ 142
- 142
src/nrf24l01/nrf24l01.cxx View File

31
 using namespace upm;
31
 using namespace upm;
32
 
32
 
33
 NRF24l01::NRF24l01 (uint8_t cs) {
33
 NRF24l01::NRF24l01 (uint8_t cs) {
34
-	maa_init();
35
-	nrfInitModule (cs, 8);
34
+    maa_init();
35
+    nrfInitModule (cs, 8);
36
 }
36
 }
37
 
37
 
38
 NRF24l01::~NRF24l01 () {
38
 NRF24l01::~NRF24l01 () {
39
-	maa_result_t error = MAA_SUCCESS;
40
-	error = maa_spi_stop(m_spi);
41
-	if (error != MAA_SUCCESS) {
39
+    maa_result_t error = MAA_SUCCESS;
40
+    error = maa_spi_stop(m_spi);
41
+    if (error != MAA_SUCCESS) {
42
         maa_result_print(error);
42
         maa_result_print(error);
43
     }
43
     }
44
-	error = maa_gpio_close (m_cePinCtx);
44
+    error = maa_gpio_close (m_cePinCtx);
45
     if (error != MAA_SUCCESS) {
45
     if (error != MAA_SUCCESS) {
46
         maa_result_print(error);
46
         maa_result_print(error);
47
     }
47
     }
48
-	error = maa_gpio_close (m_csnPinCtx);
48
+    error = maa_gpio_close (m_csnPinCtx);
49
     if (error != MAA_SUCCESS) {
49
     if (error != MAA_SUCCESS) {
50
         maa_result_print(error);
50
         maa_result_print(error);
51
     }
51
     }
53
 
53
 
54
 void
54
 void
55
 NRF24l01::nrfInitModule (uint8_t chip_select, uint8_t chip_enable) {
55
 NRF24l01::nrfInitModule (uint8_t chip_select, uint8_t chip_enable) {
56
-	maa_result_t error = MAA_SUCCESS;
56
+    maa_result_t error = MAA_SUCCESS;
57
 
57
 
58
-	m_csn 		= chip_select;
59
-	m_ce 		= chip_enable;
60
-	m_channel 	= 1;
58
+    m_csn         = chip_select;
59
+    m_ce         = chip_enable;
60
+    m_channel     = 1;
61
 
61
 
62
-	m_csnPinCtx = maa_gpio_init (m_csn);
63
-	if (m_csnPinCtx == NULL) {
62
+    m_csnPinCtx = maa_gpio_init (m_csn);
63
+    if (m_csnPinCtx == NULL) {
64
         fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_csn);
64
         fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_csn);
65
-		exit (1);
66
-	}
67
-	
68
-	m_cePinCtx = maa_gpio_init (m_ce);
69
-	if (m_cePinCtx == NULL) {
65
+        exit (1);
66
+    }
67
+    
68
+    m_cePinCtx = maa_gpio_init (m_ce);
69
+    if (m_cePinCtx == NULL) {
70
         fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_ce);
70
         fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_ce);
71
-		exit (1);
72
-	}
73
-	
74
-	error = maa_gpio_dir (m_csnPinCtx, MAA_GPIO_OUT);
71
+        exit (1);
72
+    }
73
+    
74
+    error = maa_gpio_dir (m_csnPinCtx, MAA_GPIO_OUT);
75
     if (error != MAA_SUCCESS) {
75
     if (error != MAA_SUCCESS) {
76
         maa_result_print (error);
76
         maa_result_print (error);
77
     }
77
     }
78
 
78
 
79
-	error = maa_gpio_dir (m_cePinCtx, MAA_GPIO_OUT);
79
+    error = maa_gpio_dir (m_cePinCtx, MAA_GPIO_OUT);
80
     if (error != MAA_SUCCESS) {
80
     if (error != MAA_SUCCESS) {
81
         maa_result_print (error);
81
         maa_result_print (error);
82
     }
82
     }
83
-	
84
-	nrfCELow ();
85
-	m_spi = maa_spi_init (0);
83
+    
84
+    nrfCELow ();
85
+    m_spi = maa_spi_init (0);
86
 }
86
 }
87
 
87
 
88
 void
88
 void
89
 NRF24l01::nrfConfigModule() {
89
 NRF24l01::nrfConfigModule() {
90
-	/* Set RF channel */
91
-	nrfConfigRegister (RF_CH, m_channel);
92
-
93
-	/* Set length of incoming payload */
94
-	nrfConfigRegister (RX_PW_P0, m_payload);
95
-	nrfConfigRegister (RX_PW_P1, m_payload);
96
-	/* Set length of incoming payload for broadcast */
97
-	nrfConfigRegister (RX_PW_P2, m_payload);
98
-	
99
-	/* Start receiver */
100
-	nrfPowerUpRX ();
101
-	nrfFlushRX ();
90
+    /* Set RF channel */
91
+    nrfConfigRegister (RF_CH, m_channel);
92
+
93
+    /* Set length of incoming payload */
94
+    nrfConfigRegister (RX_PW_P0, m_payload);
95
+    nrfConfigRegister (RX_PW_P1, m_payload);
96
+    /* Set length of incoming payload for broadcast */
97
+    nrfConfigRegister (RX_PW_P2, m_payload);
98
+    
99
+    /* Start receiver */
100
+    nrfPowerUpRX ();
101
+    nrfFlushRX ();
102
 }
102
 }
103
 
103
 
104
 /* Clocks only one byte into the given MiRF register */
104
 /* Clocks only one byte into the given MiRF register */
105
 void
105
 void
106
 NRF24l01::nrfConfigRegister(uint8_t reg, uint8_t value) {
106
 NRF24l01::nrfConfigRegister(uint8_t reg, uint8_t value) {
107
-	nrfCSOn ();
108
-	maa_spi_write (m_spi, W_REGISTER | (REGISTER_MASK & reg));
109
-	maa_spi_write (m_spi, value);
110
-	nrfCSOff ();
107
+    nrfCSOn ();
108
+    maa_spi_write (m_spi, W_REGISTER | (REGISTER_MASK & reg));
109
+    maa_spi_write (m_spi, value);
110
+    nrfCSOff ();
111
 }
111
 }
112
 
112
 
113
 void
113
 void
114
 NRF24l01::nrfPowerUpRX() {
114
 NRF24l01::nrfPowerUpRX() {
115
-	m_ptx = 0;
116
-	nrfCELow();
117
-	nrfConfigRegister(CONFIG, mirf_CONFIG | ( (1<<PWR_UP) | (1<<PRIM_RX) ) );
118
-	nrfCEHigh();
119
-	nrfConfigRegister(STATUS,(1 << TX_DS) | (1 << MAX_RT));
115
+    m_ptx = 0;
116
+    nrfCELow();
117
+    nrfConfigRegister(CONFIG, mirf_CONFIG | ( (1<<PWR_UP) | (1<<PRIM_RX) ) );
118
+    nrfCEHigh();
119
+    nrfConfigRegister(STATUS,(1 << TX_DS) | (1 << MAX_RT));
120
 }
120
 }
121
 
121
 
122
 void
122
 void
123
 NRF24l01::nrfFlushRX() {
123
 NRF24l01::nrfFlushRX() {
124
-	nrfCSOn ();
125
-	maa_spi_write (m_spi, FLUSH_RX);
126
-	nrfCSOff ();
124
+    nrfCSOn ();
125
+    maa_spi_write (m_spi, FLUSH_RX);
126
+    nrfCSOff ();
127
 }
127
 }
128
 
128
 
129
 /* Sets the receiving address */
129
 /* Sets the receiving address */
130
 void
130
 void
131
 NRF24l01::nrfSetRXaddr(uint8_t * addr) {
131
 NRF24l01::nrfSetRXaddr(uint8_t * addr) {
132
-	nrfCELow();
133
-	nrfWriteRegister(RX_ADDR_P1, addr, mirf_ADDR_LEN);
134
-	nrfCEHigh();
132
+    nrfCELow();
133
+    nrfWriteRegister(RX_ADDR_P1, addr, mirf_ADDR_LEN);
134
+    nrfCEHigh();
135
 }
135
 }
136
 
136
 
137
 /* Sets the transmitting address */
137
 /* Sets the transmitting address */
138
 void
138
 void
139
 NRF24l01::nrfSetTXaddr(uint8_t * addr)
139
 NRF24l01::nrfSetTXaddr(uint8_t * addr)
140
 {
140
 {
141
-	/* RX_ADDR_P0 must be set to the sending addr for auto ack to work. */
142
-	nrfWriteRegister (RX_ADDR_P0, addr, mirf_ADDR_LEN);
143
-	nrfWriteRegister (TX_ADDR, addr, mirf_ADDR_LEN);
141
+    /* RX_ADDR_P0 must be set to the sending addr for auto ack to work. */
142
+    nrfWriteRegister (RX_ADDR_P0, addr, mirf_ADDR_LEN);
143
+    nrfWriteRegister (TX_ADDR, addr, mirf_ADDR_LEN);
144
 }
144
 }
145
 
145
 
146
 /* The broadcast address should be 0xFFFFF */
146
 /* The broadcast address should be 0xFFFFF */
147
 void
147
 void
148
 NRF24l01::nrfSetBroadcastAddr (uint8_t * addr) {
148
 NRF24l01::nrfSetBroadcastAddr (uint8_t * addr) {
149
-	nrfCELow ();
150
-	nrfWriteRegister (RX_ADDR_P2, addr, mirf_ADDR_LEN);
151
-	nrfCEHigh ();
149
+    nrfCELow ();
150
+    nrfWriteRegister (RX_ADDR_P2, addr, mirf_ADDR_LEN);
151
+    nrfCEHigh ();
152
 }
152
 }
153
 
153
 
154
 void
154
 void
155
 NRF24l01::nrfSetPayload (uint8_t load) {
155
 NRF24l01::nrfSetPayload (uint8_t load) {
156
-	m_payload = load;
156
+    m_payload = load;
157
 }
157
 }
158
 
158
 
159
 void
159
 void
160
 NRF24l01::nrfWriteRegister(uint8_t reg, uint8_t * value, uint8_t len)
160
 NRF24l01::nrfWriteRegister(uint8_t reg, uint8_t * value, uint8_t len)
161
 {
161
 {
162
-	nrfCSOn ();
163
-	maa_spi_write (m_spi, W_REGISTER | (REGISTER_MASK & reg));
164
-	nrfTransmitSync(value, len);
165
-	nrfCSOff ();
162
+    nrfCSOn ();
163
+    maa_spi_write (m_spi, W_REGISTER | (REGISTER_MASK & reg));
164
+    nrfTransmitSync(value, len);
165
+    nrfCSOff ();
166
 }
166
 }
167
 
167
 
168
 void
168
 void
169
 NRF24l01::nrfTransmitSync(uint8_t *dataout, uint8_t len){
169
 NRF24l01::nrfTransmitSync(uint8_t *dataout, uint8_t len){
170
-	uint8_t i;
171
-	for(i = 0; i < len; i++) {
172
-		maa_spi_write (m_spi, dataout[i]);
173
-	}
170
+    uint8_t i;
171
+    for(i = 0; i < len; i++) {
172
+        maa_spi_write (m_spi, dataout[i]);
173
+    }
174
 }
174
 }
175
 
175
 
176
 /* Checks if data is available for reading */
176
 /* Checks if data is available for reading */
177
 bool
177
 bool
178
 NRF24l01::nrfDataReady() {
178
 NRF24l01::nrfDataReady() {
179
-	uint8_t status = nrfGetStatus();
180
-	if ( status & (1 << RX_DR) ) {
181
-		return 1;
182
-	}
183
-	
184
-	return !nrfRXFifoEmpty();
179
+    uint8_t status = nrfGetStatus();
180
+    if ( status & (1 << RX_DR) ) {
181
+        return 1;
182
+    }
183
+    
184
+    return !nrfRXFifoEmpty();
185
 }
185
 }
186
 
186
 
187
 uint8_t
187
 uint8_t
188
 NRF24l01::nrfGetStatus () {
188
 NRF24l01::nrfGetStatus () {
189
-	uint8_t rv;
190
-	nrfReadRegister (STATUS, &rv, 1);
191
-	return rv;
189
+    uint8_t rv;
190
+    nrfReadRegister (STATUS, &rv, 1);
191
+    return rv;
192
 }
192
 }
193
 
193
 
194
 /* Reads an array of bytes from the given start position in the MiRF registers. */
194
 /* Reads an array of bytes from the given start position in the MiRF registers. */
195
 void
195
 void
196
 NRF24l01::nrfReadRegister (uint8_t reg, uint8_t * value, uint8_t len)
196
 NRF24l01::nrfReadRegister (uint8_t reg, uint8_t * value, uint8_t len)
197
 {
197
 {
198
-	nrfCSOn ();
199
-	maa_spi_write (m_spi, R_REGISTER | (REGISTER_MASK & reg));
200
-	nrfTransferSync (value, value, len);
201
-	nrfCSOff ();
198
+    nrfCSOn ();
199
+    maa_spi_write (m_spi, R_REGISTER | (REGISTER_MASK & reg));
200
+    nrfTransferSync (value, value, len);
201
+    nrfCSOff ();
202
 }
202
 }
203
 
203
 
204
 void
204
 void
205
 NRF24l01::nrfTransferSync (uint8_t *dataout,uint8_t *datain,uint8_t len) {
205
 NRF24l01::nrfTransferSync (uint8_t *dataout,uint8_t *datain,uint8_t len) {
206
-	uint8_t i;
207
-	for(i = 0;i < len;i++) {
208
-		datain[i] = maa_spi_write (m_spi, dataout[i]);
209
-	}
206
+    uint8_t i;
207
+    for(i = 0;i < len;i++) {
208
+        datain[i] = maa_spi_write (m_spi, dataout[i]);
209
+    }
210
 }
210
 }
211
 
211
 
212
 bool
212
 bool
213
 NRF24l01::nrfRXFifoEmpty () {
213
 NRF24l01::nrfRXFifoEmpty () {
214
-	uint8_t fifo_status;
215
-	nrfReadRegister (FIFO_STATUS, &fifo_status, sizeof(fifo_status));
216
-	return (fifo_status & (1 << RX_EMPTY));
214
+    uint8_t fifo_status;
215
+    nrfReadRegister (FIFO_STATUS, &fifo_status, sizeof(fifo_status));
216
+    return (fifo_status & (1 << RX_EMPTY));
217
 }
217
 }
218
 
218
 
219
 /* Reads payload bytes into data array */
219
 /* Reads payload bytes into data array */
220
 void
220
 void
221
 NRF24l01::nrfGetData (uint8_t * data)
221
 NRF24l01::nrfGetData (uint8_t * data)
222
 {
222
 {
223
-	nrfCSOn ();
224
-	/* Send cmd to read rx payload */
225
-	maa_spi_write (m_spi, R_RX_PAYLOAD);
226
-	/* Read payload */
227
-	nrfTransferSync(data, data, m_payload);
228
-	nrfCSOff ();
229
-	nrfConfigRegister(STATUS, (1<<RX_DR));
223
+    nrfCSOn ();
224
+    /* Send cmd to read rx payload */
225
+    maa_spi_write (m_spi, R_RX_PAYLOAD);
226
+    /* Read payload */
227
+    nrfTransferSync(data, data, m_payload);
228
+    nrfCSOff ();
229
+    nrfConfigRegister(STATUS, (1<<RX_DR));
230
 }
230
 }
231
 
231
 
232
 /* Sends a data package to the default address. Be sure to send the correct
232
 /* Sends a data package to the default address. Be sure to send the correct
233
  * amount of bytes as configured as payload on the receiver. */
233
  * amount of bytes as configured as payload on the receiver. */
234
 void
234
 void
235
 NRF24l01::nrfSend(uint8_t * value) {
235
 NRF24l01::nrfSend(uint8_t * value) {
236
-	uint8_t status;
237
-	status = nrfGetStatus();
238
-
239
-	while (m_ptx) {
240
-		status = nrfGetStatus();
241
-
242
-		if((status & ((1 << TX_DS)  | (1 << MAX_RT)))){
243
-			m_ptx = 0;
244
-			break;
245
-		}
246
-	} // Wait until last paket is send
247
-
248
-	nrfCELow();
249
-	nrfPowerUpTX();							// Set to transmitter mode , Power up
250
-	nrfCSOn ();
251
-	maa_spi_write (m_spi, FLUSH_TX);		// Write cmd to flush tx fifo
252
-	nrfCSOff ();
253
-	
254
-	nrfCSOn ();
255
-	maa_spi_write (m_spi, W_TX_PAYLOAD); 	// Write cmd to write payload
256
-	nrfTransmitSync(value, m_payload);		// Write payload
257
-	nrfCSOff ();
258
-	nrfCEHigh();							// Start transmission
236
+    uint8_t status;
237
+    status = nrfGetStatus();
238
+
239
+    while (m_ptx) {
240
+        status = nrfGetStatus();
241
+
242
+        if((status & ((1 << TX_DS)  | (1 << MAX_RT)))){
243
+            m_ptx = 0;
244
+            break;
245
+        }
246
+    } // Wait until last paket is send
247
+
248
+    nrfCELow();
249
+    nrfPowerUpTX();                            // Set to transmitter mode , Power up
250
+    nrfCSOn ();
251
+    maa_spi_write (m_spi, FLUSH_TX);        // Write cmd to flush tx fifo
252
+    nrfCSOff ();
253
+    
254
+    nrfCSOn ();
255
+    maa_spi_write (m_spi, W_TX_PAYLOAD);     // Write cmd to write payload
256
+    nrfTransmitSync(value, m_payload);        // Write payload
257
+    nrfCSOff ();
258
+    nrfCEHigh();                            // Start transmission
259
 }
259
 }
260
 
260
 
261
 void
261
 void
262
 NRF24l01::nrfSend () {
262
 NRF24l01::nrfSend () {
263
-	nrfSend (m_txBuffer);
263
+    nrfSend (m_txBuffer);
264
 }
264
 }
265
 
265
 
266
 bool
266
 bool
267
 NRF24l01::nrfIsSending () {
267
 NRF24l01::nrfIsSending () {
268
-	uint8_t status;
269
-	if (m_ptx)	{ // Sending mode.
270
-		status = nrfGetStatus();
271
-		/* if sending successful (TX_DS) or max retries exceded (MAX_RT). */
272
-		if((status & ((1 << TX_DS)  | (1 << MAX_RT)))){
273
-			nrfPowerUpRX();
274
-			return false;
275
-		}
276
-		return true;
277
-	}
278
-	return false;
268
+    uint8_t status;
269
+    if (m_ptx)    { // Sending mode.
270
+        status = nrfGetStatus();
271
+        /* if sending successful (TX_DS) or max retries exceded (MAX_RT). */
272
+        if((status & ((1 << TX_DS)  | (1 << MAX_RT)))){
273
+            nrfPowerUpRX();
274
+            return false;
275
+        }
276
+        return true;
277
+    }
278
+    return false;
279
 }
279
 }
280
 
280
 
281
 void
281
 void
282
 NRF24l01::nrfPowerUpTX () {
282
 NRF24l01::nrfPowerUpTX () {
283
-	m_ptx = 1;
284
-	nrfConfigRegister (CONFIG, mirf_CONFIG | ( (1<<PWR_UP) | (0<<PRIM_RX) ) );
283
+    m_ptx = 1;
284
+    nrfConfigRegister (CONFIG, mirf_CONFIG | ( (1<<PWR_UP) | (0<<PRIM_RX) ) );
285
 }
285
 }
286
 
286
 
287
 void
287
 void
288
 NRF24l01::nrfPowerDown () {
288
 NRF24l01::nrfPowerDown () {
289
-	nrfCELow ();
290
-	nrfConfigRegister (CONFIG, mirf_CONFIG);
289
+    nrfCELow ();
290
+    nrfConfigRegister (CONFIG, mirf_CONFIG);
291
 }
291
 }
292
 
292
 
293
 maa_result_t
293
 maa_result_t
294
 NRF24l01::nrfCEHigh () {
294
 NRF24l01::nrfCEHigh () {
295
-	return maa_gpio_write (m_cePinCtx, HIGH);
295
+    return maa_gpio_write (m_cePinCtx, HIGH);
296
 }
296
 }
297
 
297
 
298
 maa_result_t
298
 maa_result_t
299
 NRF24l01::nrfCELow () {
299
 NRF24l01::nrfCELow () {
300
-	return maa_gpio_write (m_cePinCtx, LOW);
300
+    return maa_gpio_write (m_cePinCtx, LOW);
301
 }
301
 }
302
 
302
 
303
 maa_result_t
303
 maa_result_t
304
 NRF24l01::nrfCSOn () {
304
 NRF24l01::nrfCSOn () {
305
-	return maa_gpio_write (m_csnPinCtx, LOW);
305
+    return maa_gpio_write (m_csnPinCtx, LOW);
306
 }
306
 }
307
 
307
 
308
 maa_result_t
308
 maa_result_t
309
 NRF24l01::nrfCSOff () {
309
 NRF24l01::nrfCSOff () {
310
-	return maa_gpio_write (m_csnPinCtx, HIGH);
310
+    return maa_gpio_write (m_csnPinCtx, HIGH);
311
 }
311
 }
312
 
312
 
313
 void
313
 void
314
 NRF24l01::nrfListenForChannel() {
314
 NRF24l01::nrfListenForChannel() {
315
-	if(!nrfIsSending() && nrfDataReady()) {
316
-		nrfGetData(m_rxBuffer);
317
-		dataRecievedHandler(); /* let know that data arrived */
318
-	}
315
+    if(!nrfIsSending() && nrfDataReady()) {
316
+        nrfGetData(m_rxBuffer);
317
+        dataRecievedHandler(); /* let know that data arrived */
318
+    }
319
 }
319
 }
320
 
320
 

+ 127
- 127
src/nrf24l01/nrf24l01.h View File

29
 #include <maa/spi.h>
29
 #include <maa/spi.h>
30
 
30
 
31
 /* Memory Map */
31
 /* Memory Map */
32
-#define CONFIG      		0x00
33
-#define EN_AA       		0x01
34
-#define EN_RXADDR   		0x02
35
-#define SETUP_AW    		0x03
36
-#define SETUP_RETR  		0x04
37
-#define RF_CH       		0x05
38
-#define RF_SETUP    		0x06
39
-#define STATUS      		0x07
40
-#define OBSERVE_TX  		0x08
41
-#define CD          		0x09
42
-#define RX_ADDR_P0  		0x0A
43
-#define RX_ADDR_P1  		0x0B
44
-#define RX_ADDR_P2  		0x0C
45
-#define RX_ADDR_P3  		0x0D
46
-#define RX_ADDR_P4  		0x0E
47
-#define RX_ADDR_P5  		0x0F
48
-#define TX_ADDR     		0x10
49
-#define RX_PW_P0    		0x11
50
-#define RX_PW_P1    		0x12
51
-#define RX_PW_P2    		0x13
52
-#define RX_PW_P3    		0x14
53
-#define RX_PW_P4    		0x15
54
-#define RX_PW_P5    		0x16
55
-#define FIFO_STATUS 		0x17
32
+#define CONFIG              0x00
33
+#define EN_AA               0x01
34
+#define EN_RXADDR           0x02
35
+#define SETUP_AW            0x03
36
+#define SETUP_RETR          0x04
37
+#define RF_CH               0x05
38
+#define RF_SETUP            0x06
39
+#define STATUS              0x07
40
+#define OBSERVE_TX          0x08
41
+#define CD                  0x09
42
+#define RX_ADDR_P0          0x0A
43
+#define RX_ADDR_P1          0x0B
44
+#define RX_ADDR_P2          0x0C
45
+#define RX_ADDR_P3          0x0D
46
+#define RX_ADDR_P4          0x0E
47
+#define RX_ADDR_P5          0x0F
48
+#define TX_ADDR             0x10
49
+#define RX_PW_P0            0x11
50
+#define RX_PW_P1            0x12
51
+#define RX_PW_P2            0x13
52
+#define RX_PW_P3            0x14
53
+#define RX_PW_P4            0x15
54
+#define RX_PW_P5            0x16
55
+#define FIFO_STATUS         0x17
56
 
56
 
57
 /* Bit Mnemonics */
57
 /* Bit Mnemonics */
58
-#define MASK_RX_DR  		6
59
-#define MASK_TX_DS  		5
60
-#define MASK_MAX_RT 		4
61
-#define EN_CRC      		3
62
-#define CRCO        		2
63
-#define PWR_UP      		1
64
-#define PRIM_RX     		0
65
-#define ENAA_P5     		5
66
-#define ENAA_P4     		4
67
-#define ENAA_P3     		3
68
-#define ENAA_P2     		2
69
-#define ENAA_P1     		1
70
-#define ENAA_P0     		0
71
-#define ERX_P5      		5
72
-#define ERX_P4      		4
73
-#define ERX_P3      		3
74
-#define ERX_P2      		2
75
-#define ERX_P1      		1
76
-#define ERX_P0      		0
77
-#define AW          		0
78
-#define ARD         		4
79
-#define ARC         		0
80
-#define PLL_LOCK    		4
81
-#define RF_DR       		3
82
-#define RF_PWR      		1
83
-#define LNA_HCURR   		0
84
-#define RX_DR       		6
85
-#define TX_DS       		5
86
-#define MAX_RT      		4
87
-#define RX_P_NO     		1
88
-#define TX_FULL     		0
89
-#define PLOS_CNT    		4
90
-#define ARC_CNT     		0
91
-#define TX_REUSE    		6
92
-#define FIFO_FULL   		5
93
-#define TX_EMPTY    		4
94
-#define RX_FULL     		1
95
-#define RX_EMPTY    		0
58
+#define MASK_RX_DR          6
59
+#define MASK_TX_DS          5
60
+#define MASK_MAX_RT         4
61
+#define EN_CRC              3
62
+#define CRCO                2
63
+#define PWR_UP              1
64
+#define PRIM_RX             0
65
+#define ENAA_P5             5
66
+#define ENAA_P4             4
67
+#define ENAA_P3             3
68
+#define ENAA_P2             2
69
+#define ENAA_P1             1
70
+#define ENAA_P0             0
71
+#define ERX_P5              5
72
+#define ERX_P4              4
73
+#define ERX_P3              3
74
+#define ERX_P2              2
75
+#define ERX_P1              1
76
+#define ERX_P0              0
77
+#define AW                  0
78
+#define ARD                 4
79
+#define ARC                 0
80
+#define PLL_LOCK            4
81
+#define RF_DR               3
82
+#define RF_PWR              1
83
+#define LNA_HCURR           0
84
+#define RX_DR               6
85
+#define TX_DS               5
86
+#define MAX_RT              4
87
+#define RX_P_NO             1
88
+#define TX_FULL             0
89
+#define PLOS_CNT            4
90
+#define ARC_CNT             0
91
+#define TX_REUSE            6
92
+#define FIFO_FULL           5
93
+#define TX_EMPTY            4
94
+#define RX_FULL             1
95
+#define RX_EMPTY            0
96
 
96
 
97
 /* Instruction Mnemonics */
97
 /* Instruction Mnemonics */
98
-#define R_REGISTER    		0x00
99
-#define W_REGISTER    		0x20
100
-#define REGISTER_MASK 		0x1F
101
-#define R_RX_PAYLOAD  		0x61
102
-#define W_TX_PAYLOAD  		0xA0
103
-#define FLUSH_TX      		0xE1
104
-#define FLUSH_RX      		0xE2
105
-#define REUSE_TX_PL   		0xE3
106
-#define NOP           		0xFF
98
+#define R_REGISTER            0x00
99
+#define W_REGISTER            0x20
100
+#define REGISTER_MASK         0x1F
101
+#define R_RX_PAYLOAD          0x61
102
+#define W_TX_PAYLOAD          0xA0
103
+#define FLUSH_TX              0xE1
104
+#define FLUSH_RX              0xE2
105
+#define REUSE_TX_PL           0xE3
106
+#define NOP                   0xFF
107
 
107
 
108
 /* Nrf24l settings */
108
 /* Nrf24l settings */
109
-#define mirf_ADDR_LEN		5
110
-#define mirf_CONFIG 		((1<<EN_CRC) | (0<<CRCO) )
109
+#define mirf_ADDR_LEN        5
110
+#define mirf_CONFIG         ((1<<EN_CRC) | (0<<CRCO) )
111
 
111
 
112
-#define MAX_BUFFER			32
112
+#define MAX_BUFFER            32
113
 
113
 
114
-#define HIGH          		1
115
-#define LOW	        		0
114
+#define HIGH                  1
115
+#define LOW                    0
116
 
116
 
117
 namespace upm {
117
 namespace upm {
118
 
118
 
120
 
120
 
121
 class NRF24l01 {
121
 class NRF24l01 {
122
     public:
122
     public:
123
-		NRF24l01 (uint8_t cs);
124
-		~NRF24l01 ();
125
-		std::string name()
123
+        NRF24l01 (uint8_t cs);
124
+        ~NRF24l01 ();
125
+        std::string name()
126
         {
126
         {
127
             return m_name;
127
             return m_name;
128
         }
128
         }
129
 
129
 
130
-		void nrfInitModule (uint8_t chipSelect, uint8_t chipEnable);
131
-		void nrfConfigModule ();
132
-		void nrfSend (uint8_t *value);
133
-		void nrfSend ();
134
-		void nrfSetRXaddr (uint8_t * addr);
135
-		void nrfSetTXaddr (uint8_t * addr);
136
-		void nrfSetBroadcastAddr (uint8_t * addr);
137
-		void nrfSetPayload (uint8_t load);
138
-		bool nrfDataReady ();
139
-		bool nrfIsSending ();
140
-		bool nrfRXFifoEmpty ();
141
-		bool nrfTXFifoEmpty ();
142
-		void nrfGetData (uint8_t * data);
143
-		uint8_t nrfGetStatus ();
144
-		
145
-		void nrfTransmitSync (uint8_t *dataout, uint8_t len);
146
-		void nrfTransferSync (uint8_t *dataout ,uint8_t *datain, uint8_t len);
147
-		void nrfConfigRegister (uint8_t reg, uint8_t value);
148
-		void nrfReadRegister (uint8_t reg, uint8_t * value, uint8_t len);
149
-		void nrfWriteRegister (uint8_t reg, uint8_t * value, uint8_t len);
150
-		void nrfPowerUpRX ();
151
-		void nrfPowerUpTX ();
152
-		void nrfPowerDown ();
153
-
154
-		maa_result_t nrfCEHigh ();
155
-		maa_result_t nrfCELow ();
156
-		maa_result_t nrfCSOn ();
157
-		maa_result_t nrfCSOff ();
158
-		void nrfFlushRX ();
159
-		void nrfListenForChannel();
160
-
161
-		uint8_t				m_rxBuffer[MAX_BUFFER];
162
-		uint8_t				m_txBuffer[MAX_BUFFER];
163
-
164
-		funcPtrVoidVoid dataRecievedHandler;
165
-	private:
166
-		maa_spi_context		m_spi;
167
-		uint8_t				m_ce;
168
-		uint8_t				m_csn;
169
-		uint8_t				m_channel;
170
-		uint8_t 			m_ptx;
171
-		uint8_t				m_payload;
172
-		uint8_t				m_localAddress[5];
173
-		
174
-		maa_gpio_context 	m_csnPinCtx;
175
-		maa_gpio_context 	m_cePinCtx;
176
-
177
-		std::string 		m_name;
130
+        void nrfInitModule (uint8_t chipSelect, uint8_t chipEnable);
131
+        void nrfConfigModule ();
132
+        void nrfSend (uint8_t *value);
133
+        void nrfSend ();
134
+        void nrfSetRXaddr (uint8_t * addr);
135
+        void nrfSetTXaddr (uint8_t * addr);
136
+        void nrfSetBroadcastAddr (uint8_t * addr);
137
+        void nrfSetPayload (uint8_t load);
138
+        bool nrfDataReady ();
139
+        bool nrfIsSending ();
140
+        bool nrfRXFifoEmpty ();
141
+        bool nrfTXFifoEmpty ();
142
+        void nrfGetData (uint8_t * data);
143
+        uint8_t nrfGetStatus ();
144
+        
145
+        void nrfTransmitSync (uint8_t *dataout, uint8_t len);
146
+        void nrfTransferSync (uint8_t *dataout ,uint8_t *datain, uint8_t len);
147
+        void nrfConfigRegister (uint8_t reg, uint8_t value);
148
+        void nrfReadRegister (uint8_t reg, uint8_t * value, uint8_t len);
149
+        void nrfWriteRegister (uint8_t reg, uint8_t * value, uint8_t len);
150
+        void nrfPowerUpRX ();
151
+        void nrfPowerUpTX ();
152
+        void nrfPowerDown ();
153
+
154
+        maa_result_t nrfCEHigh ();
155
+        maa_result_t nrfCELow ();
156
+        maa_result_t nrfCSOn ();
157
+        maa_result_t nrfCSOff ();
158
+        void nrfFlushRX ();
159
+        void nrfListenForChannel();
160
+
161
+        uint8_t                m_rxBuffer[MAX_BUFFER];
162
+        uint8_t                m_txBuffer[MAX_BUFFER];
163
+
164
+        funcPtrVoidVoid dataRecievedHandler;
165
+    private:
166
+        maa_spi_context        m_spi;
167
+        uint8_t                m_ce;
168
+        uint8_t                m_csn;
169
+        uint8_t                m_channel;
170
+        uint8_t             m_ptx;
171
+        uint8_t                m_payload;
172
+        uint8_t                m_localAddress[5];
173
+        
174
+        maa_gpio_context     m_csnPinCtx;
175
+        maa_gpio_context     m_cePinCtx;
176
+
177
+        std::string         m_name;
178
 };
178
 };
179
 
179
 
180
 }
180
 }