Skip to content

Commit

Permalink
led: use uppercase for defines
Browse files Browse the repository at this point in the history
  • Loading branch information
marckleinebudde committed Dec 13, 2022
1 parent 16c7ca0 commit ca78d19
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
7 changes: 4 additions & 3 deletions include/led.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ typedef enum {
} led_mode_t;

typedef enum {
led_rx = 0, //will also index into array led_state[]
led_tx
LED_RX = 0, //will also index into array led_state[]
LED_TX,
LED_MAX
} led_num_t;

typedef struct {
Expand All @@ -68,7 +69,7 @@ typedef struct {
uint32_t t_sequence_next;
int32_t seq_num_repeat;

led_state_t led_state[2];
led_state_t led_state[LED_MAX];
} led_data_t;


Expand Down
4 changes: 2 additions & 2 deletions src/can_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void CAN_SendFrame(USBD_GS_CAN_HandleTypeDef *hcan, can_data_t *channel)

list_add_tail_locked(&frame_object->list, &hcan->list_to_host);

led_indicate_trx(&channel->leds, led_tx);
led_indicate_trx(&channel->leds, LED_TX);
}

void CAN_ReceiveFrame(USBD_GS_CAN_HandleTypeDef *hcan, can_data_t *channel)
Expand Down Expand Up @@ -97,7 +97,7 @@ void CAN_ReceiveFrame(USBD_GS_CAN_HandleTypeDef *hcan, can_data_t *channel)

list_add_tail_locked(&frame_object->list, &hcan->list_to_host);

led_indicate_trx(&channel->leds, led_rx);
led_indicate_trx(&channel->leds, LED_RX);
}

// If there are frames to receive, don't report any error frames. The
Expand Down
24 changes: 12 additions & 12 deletions src/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ void led_init(
void* led_tx_port, uint16_t led_tx_pin, bool led_tx_active_high
) {
memset(leds, 0, sizeof(led_data_t));
leds->led_state[led_rx].port = led_rx_port;
leds->led_state[led_rx].pin = led_rx_pin;
leds->led_state[led_rx].is_active_high = led_rx_active_high;
leds->led_state[led_tx].port = led_tx_port;
leds->led_state[led_tx].pin = led_tx_pin;
leds->led_state[led_tx].is_active_high = led_tx_active_high;
leds->led_state[LED_RX].port = led_rx_port;
leds->led_state[LED_RX].pin = led_rx_pin;
leds->led_state[LED_RX].is_active_high = led_rx_active_high;
leds->led_state[LED_TX].port = led_tx_port;
leds->led_state[LED_TX].pin = led_tx_pin;
leds->led_state[LED_TX].is_active_high = led_tx_active_high;
}

void led_set_mode(led_data_t *leds,led_mode_t mode)
Expand All @@ -65,8 +65,8 @@ static uint32_t led_set_sequence_step(led_data_t *leds, uint32_t step_num)
{
const led_seq_step_t *step = &leds->sequence[step_num];
leds->sequence_step = step_num;
led_set(&leds->led_state[led_rx], step->state & 0x01);
led_set(&leds->led_state[led_tx], step->state & 0x02);
led_set(&leds->led_state[LED_RX], step->state & 0x01);
led_set(&leds->led_state[LED_TX], step->state & 0x02);
uint32_t delta = 10 * step->time_in_10ms;
if (delta > INT32_MAX) {
delta = INT32_MAX; //clamp
Expand Down Expand Up @@ -150,13 +150,13 @@ void led_update(led_data_t *leds)
switch (leds->mode) {

case led_mode_off:
led_set(&leds->led_state[led_rx], false);
led_set(&leds->led_state[led_tx], false);
led_set(&leds->led_state[LED_RX], false);
led_set(&leds->led_state[LED_TX], false);
break;

case led_mode_normal:
led_update_normal_mode(&leds->led_state[led_rx], now);
led_update_normal_mode(&leds->led_state[led_tx], now);
led_update_normal_mode(&leds->led_state[LED_RX], now);
led_update_normal_mode(&leds->led_state[LED_TX], now);
break;

case led_mode_sequence:
Expand Down

0 comments on commit ca78d19

Please sign in to comment.