Update code style.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2023-03-04 14:10:46 +01:00
parent 3b268a33eb
commit 15569ab419
4 changed files with 38 additions and 22 deletions

View File

@@ -55,7 +55,7 @@
#define ws2812_T2 5 #define ws2812_T2 5
#define ws2812_T3 3 #define ws2812_T3 3
static const uint16_t ws2812_program_instructions[] = { static const uint16_t ws2812_program_instructions[] = {
// .wrap_target // .wrap_target
0x6221, // 0: out x, 1 side 0 [2] 0x6221, // 0: out x, 1 side 0 [2]
0x1123, // 1: jmp !x, 3 side 1 [1] 0x1123, // 1: jmp !x, 3 side 1 [1]
0x1400, // 2: jmp 0 side 1 [4] 0x1400, // 2: jmp 0 side 1 [4]
@@ -74,7 +74,12 @@ static inline pio_sm_config ws2812_program_get_default_config(uint offset) {
sm_config_set_sideset(&c, 1, false, false); sm_config_set_sideset(&c, 1, false, false);
return c; return c;
} }
static inline void ws2812_program_init(PIO pio, uint sm, uint offset, uint pin, float freq, bool rgbw) { static inline void ws2812_program_init(PIO pio,
uint sm,
uint offset,
uint pin,
float freq,
bool rgbw) {
pio_gpio_init(pio, pin); pio_gpio_init(pio, pin);
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true); pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
pio_sm_config c = ws2812_program_get_default_config(offset); pio_sm_config c = ws2812_program_get_default_config(offset);
@@ -190,7 +195,7 @@ void led_blinking_task() {
#endif #endif
#ifdef PICO_DEFAULT_LED_PIN #ifdef PICO_DEFAULT_LED_PIN
static uint8_t led_color = PICO_DEFAULT_LED_PIN; static uint8_t led_color = PICO_DEFAULT_LED_PIN;
#elif defined (PICO_DEFAULT_WS2812_PIN) #elif defined(PICO_DEFAULT_WS2812_PIN)
#endif #endif
@@ -202,11 +207,13 @@ void led_blinking_task() {
#ifdef PICO_DEFAULT_LED_PIN #ifdef PICO_DEFAULT_LED_PIN
gpio_put(led_color, led_state); gpio_put(led_color, led_state);
#elif defined (PICO_DEFAULT_WS2812_PIN) #elif defined(PICO_DEFAULT_WS2812_PIN)
if (led_state == 0) if (led_state == 0) {
pio_sm_put_blocking(pio0, 0, 0); pio_sm_put_blocking(pio0, 0, 0);
else }
else {
pio_sm_put_blocking(pio0, 0, 0xff000000); pio_sm_put_blocking(pio0, 0, 0xff000000);
}
#endif #endif
led_state ^= 1; // toggle led_state ^= 1; // toggle
} }

View File

@@ -201,7 +201,9 @@ int driver_process_usb_packet_ccid(uint16_t rx_read) {
ccid_response->abRFU1 = 0; ccid_response->abRFU1 = 0;
ccid_write(0); ccid_write(0);
} }
else if (ccid_header->bMessageType == CCID_SET_PARAMS || ccid_header->bMessageType == CCID_GET_PARAMS || ccid_header->bMessageType == CCID_RESET_PARAMS) { else if (ccid_header->bMessageType == CCID_SET_PARAMS ||
ccid_header->bMessageType == CCID_GET_PARAMS ||
ccid_header->bMessageType == CCID_RESET_PARAMS) {
/* Values from gnuk. Not specified in ICCD spec. */ /* Values from gnuk. Not specified in ICCD spec. */
const uint8_t params[] = { const uint8_t params[] = {
0x11, /* bmFindexDindex */ 0x11, /* bmFindexDindex */
@@ -298,11 +300,13 @@ static uint16_t ccid_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc,
memcpy(itf_vendor, itf_desc, sizeof(uint8_t) * max_len); memcpy(itf_vendor, itf_desc, sizeof(uint8_t) * max_len);
((tusb_desc_interface_t *) itf_vendor)->bInterfaceClass = TUSB_CLASS_VENDOR_SPECIFIC; ((tusb_desc_interface_t *) itf_vendor)->bInterfaceClass = TUSB_CLASS_VENDOR_SPECIFIC;
((tusb_desc_interface_t *) itf_vendor)->bNumEndpoints -= 1; ((tusb_desc_interface_t *) itf_vendor)->bNumEndpoints -= 1;
vendord_open(rhport, (tusb_desc_interface_t *) itf_vendor, max_len-sizeof(tusb_desc_endpoint_t)); vendord_open(rhport,
(tusb_desc_interface_t *) itf_vendor,
max_len - sizeof(tusb_desc_endpoint_t));
TU_ASSERT(usbd_edpt_open(rhport, &desc_ep3), 0); TU_ASSERT(usbd_edpt_open(rhport, &desc_ep3), 0);
free(itf_vendor); free(itf_vendor);
uint8_t msg[] = {0x50, 0x03}; uint8_t msg[] = { 0x50, 0x03 };
usbd_edpt_xfer(rhport, desc_ep3.bEndpointAddress, msg, sizeof(msg)); usbd_edpt_xfer(rhport, desc_ep3.bEndpointAddress, msg, sizeof(msg));
uint16_t const drv_len = sizeof(tusb_desc_interface_t) + sizeof(struct ccid_class_descriptor) + uint16_t const drv_len = sizeof(tusb_desc_interface_t) + sizeof(struct ccid_class_descriptor) +

View File

@@ -118,7 +118,7 @@ int emul_init(char *host, uint16_t port) {
server_sockaddr.sin_addr.s_addr = htonl(INADDR_ANY); server_sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
if (bind(hid_server_sock, (struct sockaddr *) &server_sockaddr, if (bind(hid_server_sock, (struct sockaddr *) &server_sockaddr,
sizeof server_sockaddr) != 0) { sizeof server_sockaddr) != 0) {
perror("bind"); perror("bind");
close(hid_server_sock); close(hid_server_sock);
return 1; return 1;
@@ -134,16 +134,19 @@ int emul_init(char *host, uint16_t port) {
uint8_t *driver_prepare_response_emul(uint8_t itf) { uint8_t *driver_prepare_response_emul(uint8_t itf) {
apdu.rdata = usb_get_tx(itf); apdu.rdata = usb_get_tx(itf);
if (itf == ITF_HID) if (itf == ITF_HID) {
apdu.rdata += 7; apdu.rdata += 7;
}
return apdu.rdata; return apdu.rdata;
} }
int get_sock_itf(uint8_t itf) { int get_sock_itf(uint8_t itf) {
if (itf == ITF_CCID) if (itf == ITF_CCID) {
return ccid_sock; return ccid_sock;
else if (itf == ITF_HID) }
else if (itf == ITF_HID) {
return hid_client_sock; return hid_client_sock;
}
return -1; return -1;
} }
@@ -152,8 +155,7 @@ const uint8_t *complete_report = NULL;
uint16_t complete_len = 0; uint16_t complete_len = 0;
extern bool last_write_result; extern bool last_write_result;
extern uint16_t send_buffer_size; extern uint16_t send_buffer_size;
int driver_write_emul(uint8_t itf, const uint8_t *buffer, size_t buffer_size) int driver_write_emul(uint8_t itf, const uint8_t *buffer, size_t buffer_size) {
{
uint16_t size = htons(buffer_size); uint16_t size = htons(buffer_size);
int sock = get_sock_itf(itf); int sock = get_sock_itf(itf);
// DEBUG_PAYLOAD(buffer,buffer_size); // DEBUG_PAYLOAD(buffer,buffer_size);
@@ -232,10 +234,11 @@ int driver_process_usb_packet_emul(uint8_t itf, uint16_t len) {
} }
else if (thread_type == 2) { else if (thread_type == 2) {
apdu.sw = cbor_parse(cmd, cbor_data, cbor_len); apdu.sw = cbor_parse(cmd, cbor_data, cbor_len);
if (apdu.sw == 0) if (apdu.sw == 0) {
DEBUG_DATA(res_APDU + 1, res_APDU_size); DEBUG_DATA(res_APDU + 1, res_APDU_size);
}
finished_data_size = res_APDU_size+1; finished_data_size = res_APDU_size + 1;
} }
driver_exec_finished_hid(finished_data_size); driver_exec_finished_hid(finished_data_size);
} }
@@ -260,14 +263,16 @@ uint16_t emul_read(uint8_t itf) {
timeout = (0 * 1000 + 1000 / 1000); timeout = (0 * 1000 + 1000 / 1000);
if (poll(&pfd, 1, timeout) == -1) if (poll(&pfd, 1, timeout) == -1) {
return 0; return 0;
}
if(pfd.revents & POLLIN) { if (pfd.revents & POLLIN) {
if (hid_client_sock > 0) if (hid_client_sock > 0) {
close(hid_client_sock); close(hid_client_sock);
}
hid_client_sock = accept(hid_server_sock, (struct sockaddr *) &client_sockaddr, hid_client_sock = accept(hid_server_sock, (struct sockaddr *) &client_sockaddr,
&client_socklen); &client_socklen);
printf("hid_client connected!\n"); printf("hid_client connected!\n");
} }
} }

View File

@@ -193,7 +193,7 @@ static uint8_t desc_hid_kb[] = {
#include "apdu.h" #include "apdu.h"
uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) { uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) {
printf("report_cb %d\n", itf); printf("report_cb %d\n", itf);
DEBUG_DATA(desc_hid_report, sizeof(desc_hid_report)); DEBUG_DATA(desc_hid_report, sizeof(desc_hid_report));
if (itf == ITF_HID) { if (itf == ITF_HID) {
return desc_hid_report; return desc_hid_report;
} }