Skip to content

Commit 8c0e975

Browse files
committed
refactor: merge rgb command functions
1 parent 97693c0 commit 8c0e975

File tree

4 files changed

+51
-95
lines changed

4 files changed

+51
-95
lines changed

pslab-core.X/commands.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,14 @@ command_func_t* const cmd_table[NUM_PRIMARY_CMDS + 1][NUM_SECONDARY_CMDS_MAX + 1
243243
Undefined, Unimplemented, MULTIMETER_GetCapacitance, Unimplemented,
244244
// 4 GET_INDUCTANCE 5 GET_VERSION 6 7
245245
Unimplemented, DEVICE_GetVersion, Undefined, Undefined,
246-
// 8 RETRIEVE_BUFFER 9 GET_HIGH_FREQUENCY 10 CLEAR_BUFFER 11 SETRGB
247-
BUFFER_Retrieve, Unimplemented, Unimplemented, LIGHT_Onboard,
246+
// 8 RETRIEVE_BUFFER 9 GET_HIGH_FREQUENCY 10 CLEAR_BUFFER 11 SET_RGB1
247+
BUFFER_Retrieve, Unimplemented, Unimplemented, Removed,
248248
// 12 READ_PROGRAM_ADDRESS 13 WRITE_PROGRAM_ADDRESS 14 READ_DATA_ADDRESS 15 WRITE_DATA_ADDRESS
249249
Removed, Removed, DEVICE_ReadRegisterData, DEVICE_WriteRegisterData,
250-
// 16 GET_CAP_RANGE 17 SETRGB2 18 READ_LOG 19 RESTORE_STANDALONE
251-
Unimplemented, LIGHT_One, Removed, DEVICE_Reset,
252-
// 20 GET_ALTERNATE_HIGH_FREQUENCY 21 22 SETRGB3 23 START_CTMU
253-
Unimplemented, Undefined, LIGHT_Two, Unimplemented,
250+
// 16 GET_CAP_RANGE 17 SET_RGB2 18 READ_LOG 19 RESTORE_STANDALONE
251+
Unimplemented, Removed, Removed, DEVICE_Reset,
252+
// 20 GET_ALTERNATE_HIGH_FREQUENCY 21 SET_RGB_COMMON 22 SET_RGB3 23 START_CTMU
253+
Unimplemented, LIGHT_RGBPin, Removed, Unimplemented,
254254
// 24 STOP_CTMU 25 START_COUNTING 26 FETCH_COUNT 27 FILL_BUFFER
255255
Unimplemented, SENSORS_StartCounter, SENSORS_GetCounter, Unimplemented,
256256
},

pslab-core.X/helpers/light.c

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -49,66 +49,50 @@
4949
}\
5050
} while(0)
5151

52+
typedef enum {
53+
ONBOARD,
54+
SQR1,
55+
SQR2,
56+
SQR3,
57+
SQR4,
58+
} PINSELECT;
59+
5260
void LIGHT_RGB(uint8_t red, uint8_t green, uint8_t blue) {
5361
RGBCommon(red, green, blue, RGB_LED_Setter);
5462
}
5563

56-
response_t LIGHT_Onboard(void) {
57-
58-
uint8_t count = UART1_Read();
59-
uint8_t colors[count];
60-
61-
uint8_t i;
62-
for (i = 0; i < count; i++) {
63-
colors[i] = UART1_Read();
64-
}
65-
66-
INTERRUPT_GlobalDisable();
67-
68-
for (i = 0; i < count; i = i + 3) {
69-
RGBCommon(colors[i+1], colors[i], colors[i+2], RGB_LED_Setter);
70-
}
71-
72-
INTERRUPT_GlobalEnable();
73-
74-
return SUCCESS;
75-
}
76-
77-
response_t LIGHT_One(void) {
78-
79-
uint8_t count = UART1_Read();
80-
uint8_t colors[count];
81-
82-
uint8_t i;
83-
for (i = 0; i < count; i++) {
84-
colors[i] = UART1_Read();
85-
}
86-
87-
INTERRUPT_GlobalDisable();
88-
89-
for (i = 0; i < count; i = i + 3) {
90-
RGBCommon(colors[i+1], colors[i], colors[i+2], SQR1_Setter);
91-
}
92-
93-
INTERRUPT_GlobalEnable();
94-
95-
return SUCCESS;
96-
}
97-
98-
response_t LIGHT_Two(void) {
99-
64+
response_t LIGHT_RGBPin(void) {
10065
uint8_t count = UART1_Read();
10166
uint8_t colors[count];
10267

10368
uint8_t i;
10469
for (i = 0; i < count; i++) {
10570
colors[i] = UART1_Read();
10671
}
72+
PINSELECT pin = UART1_Read();
10773

10874
INTERRUPT_GlobalDisable();
10975

11076
for (i = 0; i < count; i = i + 3) {
111-
RGBCommon(colors[i+1], colors[i], colors[i+2], SQR2_Setter);
77+
switch (pin) {
78+
case ONBOARD:
79+
RGBCommon(colors[i+1], colors[i], colors[i+2], RGB_LED_Setter);
80+
break;
81+
case SQR1:
82+
RGBCommon(colors[i+1], colors[i], colors[i+2], SQR1_Setter);
83+
break;
84+
case SQR2:
85+
RGBCommon(colors[i+1], colors[i], colors[i+2], SQR2_Setter);
86+
break;
87+
case SQR3:
88+
RGBCommon(colors[i+1], colors[i], colors[i+2], SQR3_Setter);
89+
break;
90+
case SQR4:
91+
RGBCommon(colors[i+1], colors[i], colors[i+2], SQR4_Setter);
92+
break;
93+
default:
94+
break;
95+
}
11296
}
11397

11498
INTERRUPT_GlobalEnable();

pslab-core.X/helpers/light.h

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,56 +25,26 @@ extern "C" {
2525
* @brief Controls the on-board RGB LED
2626
*
2727
* @description
28-
* This routine takes two types of arguments over serial.
29-
* 1. (uint8) count
30-
* Number of color levels. This always has to be 3. It is implemented this
31-
* way to have backward compatibility with old firmware and python backend.
32-
* 2. (uint8 [count]) color levels
33-
* This a sequence of bytes with the amount determined by count variable.
34-
* In this case it will be three bytes in series. These will define red, green
35-
* and blue colors of the LED.
36-
*
37-
* It will not return anything over serial. An acknowledgment will be passed.
38-
*
39-
* @return none
40-
*/
41-
response_t LIGHT_Onboard(void);
42-
43-
/**
44-
* @brief Controls an RGB LED stripe from SQR1 pin
45-
*
46-
* @description
47-
* This routine takes two types of arguments over serial.
48-
* 1. (uint8) count
49-
* Number of color levels. This has to be a multiple of 3 since each LED
50-
* has three colors to control.
51-
* 2. (uint8 [count]) color levels
52-
* This a sequence of bytes with the amount determined by count variable.
53-
* These will define red, green and blue colors of each of the LEDs.
54-
*
55-
* It will not return anything over serial. An acknowledgment will be passed.
56-
*
57-
* @return none
58-
*/
59-
response_t LIGHT_One(void);
60-
61-
/**
62-
* @brief Controls an RGB LED stripe from SQR2 pin
63-
*
64-
* @description
65-
* This routine takes two types of arguments over serial.
28+
* This routine takes three types of arguments over serial.
6629
* 1. (uint8) count
6730
* Number of color levels. This has to be a multiple of 3 since each LED
68-
* has three colors to control.
31+
* has three colors to control.
6932
* 2. (uint8 [count]) color levels
7033
* This a sequence of bytes with the amount determined by count variable.
71-
* These will define red, green and blue colors of each of the LEDs.
34+
* These will define red, green and blue colors of each of the LEDs.
35+
* 3. (uint8) pin
36+
* The pin to which the RGB LED's DIN is connected.
37+
* 0: Onboard RGB,
38+
* 1: SQ1,
39+
* 2: SQ2,
40+
* 3: SQ3,
41+
* 4: SQ4
7242
*
7343
* It will not return anything over serial. An acknowledgment will be passed.
7444
*
7545
* @return none
7646
*/
77-
response_t LIGHT_Two(void);
47+
response_t LIGHT_RGBPin(void);
7848

7949
#ifdef __cplusplus
8050
}

pslab-core.X/registers/system/pin_manager.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define LED_SetDigitalInput() (_TRISB15 = 1)
1616
#define LED_SetDigitalOutput() (_TRISB15 = 0)
1717

18-
#define RGB_LED_Setter _LATB2
18+
#define RGB_LED_Setter _LATB2
1919
#define RGB_LED_SetHigh() (_LATB2 = 1)
2020
#define RGB_LED_SetLow() (_LATB2 = 0)
2121
#define RGB_LED_Toggle() (_LATB2 ^= 1)
@@ -257,29 +257,31 @@
257257
/*******************************************************************************
258258
* Wave Generator
259259
******************************************************************************/
260-
#define SQR1_Setter _LATC6
260+
#define SQR1_Setter _LATC6
261261
#define SQR1_SetHigh() (_LATC6 = 1)
262262
#define SQR1_SetLow() (_LATC6 = 0)
263263
#define SQR1_Toggle() (_LATC6 ^= 1)
264264
#define SQR1_GetValue() _RC6
265265
#define SQR1_SetDigitalInput() (_TRISC6 = 1)
266266
#define SQR1_SetDigitalOutput() (_TRISC6 = 0)
267267

268-
#define SQR2_Setter _LATC7
268+
#define SQR2_Setter _LATC7
269269
#define SQR2_SetHigh() (_LATC7 = 1)
270270
#define SQR2_SetLow() (_LATC7 = 0)
271271
#define SQR2_Toggle() (_LATC7 ^= 1)
272272
#define SQR2_GetValue() _RC7
273273
#define SQR2_SetDigitalInput() (_TRISC7 = 1)
274274
#define SQR2_SetDigitalOutput() (_TRISC7 = 0)
275275

276+
#define SQR3_Setter _LATC8
276277
#define SQR3_SetHigh() (_LATC8 = 1)
277278
#define SQR3_SetLow() (_LATC8 = 0)
278279
#define SQR3_Toggle() (_LATC8 ^= 1)
279280
#define SQR3_GetValue() _RC8
280281
#define SQR3_SetDigitalInput() (_TRISC8 = 1)
281282
#define SQR3_SetDigitalOutput() (_TRISC8 = 0)
282283

284+
#define SQR4_Setter _LATC9
283285
#define SQR4_SetHigh() (_LATC9 = 1)
284286
#define SQR4_SetLow() (_LATC9 = 0)
285287
#define SQR4_Toggle() (_LATC9 ^= 1)

0 commit comments

Comments
 (0)