code cleanup & fix compile with pico-sdk 2.2.0

This commit is contained in:
2025-08-12 07:49:12 -04:00
parent 4f313b3336
commit 692c5af8c9
6 changed files with 28 additions and 20 deletions
-1
View File
@@ -37,7 +37,6 @@ target_sources(${PROJECT} PRIVATE
)
pico_enable_stdio_usb(${PROJECT} 1)
pico_enable_stdio_uart(${PROJECT} 1)
pico_add_extra_outputs(${PROJECT})
+3 -2
View File
@@ -1,5 +1,5 @@
#ifndef MBEDTLS_CONFIG_EXAMPLES_COMMON_H
#define MBEDTLS_CONFIG_EXAMPLES_COMMON_H
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H
/* Workaround for some mbedtls source files using INT_MAX without including limits.h */
#include <limits.h>
@@ -11,6 +11,7 @@
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
#define MBEDTLS_HAVE_TIME
#define MBEDTLS_PLATFORM_MS_TIME_ALT
#define MBEDTLS_CIPHER_MODE_CBC
#define MBEDTLS_ECP_DP_SECP192R1_ENABLED
+2
View File
@@ -7,6 +7,8 @@
#include "parse_keys.h"
#include "usb_descriptors.h"
static unsigned char boot_buf[8];
// take a list of Javascript keys representing pressed keys and turn into
// a 8 byte USB boot keyboard report format
void parse_key_list(char * keys) {
-2
View File
@@ -3,7 +3,6 @@
#define MOUSE_SPEED 10
static unsigned char boot_buf[8];
void parse_key_list(char * keys);
void parse_mouse_list(char * keys);
@@ -12,7 +11,6 @@ uint8_t parse_mod(char * key);
typedef struct { char * key; uint8_t val; } keycode_dict;
// modifier key bit codes
#define KEY_MOD_LCTRL 0x01
#define KEY_MOD_LSHIFT 0x02
+23 -1
View File
@@ -22,6 +22,21 @@ static tWSOpenHandler ws_open_cb = NULL;
static struct ws_state * ws_connections;
static uint8_t ws_num_conns = 0;
static struct ws_state* ws_state_alloc(void);
static void ws_state_init(struct ws_state *wss);
static void ws_state_free(struct ws_state *wss);
static void ws_server_init_pcb( struct altcp_pcb *pcb, uint16_t port);
static err_t ws_accept(void *arg, struct altcp_pcb *pcb, err_t err);
static err_t ws_recv(void *arg, struct altcp_pcb *pcb, struct pbuf *p, err_t err);
static err_t ws_sent(void *arg, struct altcp_pcb *pcb, uint16_t len);
static void ws_err (void *arg, err_t err);
static err_t ws_close_conn(struct altcp_pcb *pcb, struct ws_state *wss);
static err_t ws_close_or_abort_conn(struct altcp_pcb *pcb, struct ws_state *wss, uint8_t abort_conn);
static err_t ws_poll(void *arg, struct altcp_pcb *pcb);
static err_t ws_handshake(struct altcp_pcb *pcb, struct ws_state *wss, struct pbuf *p);
static err_t ws_read(struct altcp_pcb *pcb, struct ws_state *wss, struct pbuf *p);
static err_t ws_send(struct ws_state *wss, uint8_t *data, uint16_t len);
// allocate memory for ws_state instance
static struct ws_state * ws_state_alloc(void) {
struct ws_state *ret = WS_ALLOC_WS_STATE();
@@ -338,6 +353,7 @@ static err_t ws_read(struct altcp_pcb *pcb, struct ws_state *wss, struct pbuf *p
uint8_t masked = data[1] & 0x80;
uint16_t msg_len = data[1] & 0x7F;
uint8_t *msg;
switch (msg_len) {
case 126: // next two bytes are length
memcpy(&msg_len, &data[2], 2);
@@ -347,7 +363,8 @@ static err_t ws_read(struct altcp_pcb *pcb, struct ws_state *wss, struct pbuf *p
break;
case 127: // next four bytes are length
// lwIP's pbuf only handles 16-bit lengths, so error
return ERR_ARG;
LWIP_DEBUGF(WS_DEBUG, ("ws_read: received 64-bit length %u\n", msg_len));
return ERR_MEM;
//memcpy(&msg_len, &data[2], 4);
//if (len >= 10) {
@@ -387,6 +404,11 @@ static err_t ws_read(struct altcp_pcb *pcb, struct ws_state *wss, struct pbuf *p
memset(buf, 0x00, sizeof(buf));
}
if (buf_len + msg_len > WS_BUFFER_SIZE) {
LWIP_DEBUGF(WS_DEBUG, ("ws_read: message exceeds buffer size %u+%u\n", buf_len, msg_len));
return ERR_MEM;
}
memcpy(&buf[buf_len], msg, msg_len);
buf_len += msg_len;
-14
View File
@@ -28,21 +28,7 @@ struct ws_state {
typedef void (* tWSHandler ) (uint8_t *data, uint16_t len);
typedef void (* tWSOpenHandler ) (struct ws_state * wss);
static struct ws_state* ws_state_alloc(void);
static void ws_state_init(struct ws_state *wss);
static void ws_state_free(struct ws_state *wss);
void ws_server_init(void);
static void ws_server_init_pcb( struct altcp_pcb *pcb, uint16_t port);
static err_t ws_accept(void *arg, struct altcp_pcb *pcb, err_t err);
static err_t ws_recv(void *arg, struct altcp_pcb *pcb, struct pbuf *p, err_t err);
static err_t ws_sent(void *arg, struct altcp_pcb *pcb, uint16_t len);
static void ws_err (void *arg, err_t err);
static err_t ws_close_conn(struct altcp_pcb *pcb, struct ws_state *wss);
static err_t ws_close_or_abort_conn(struct altcp_pcb *pcb, struct ws_state *wss, uint8_t abort_conn);
static err_t ws_poll(void *arg, struct altcp_pcb *pcb);
static err_t ws_handshake(struct altcp_pcb *pcb, struct ws_state *wss, struct pbuf *p);
static err_t ws_read(struct altcp_pcb *pcb, struct ws_state *wss, struct pbuf *p);
static err_t ws_send(struct ws_state *wss, uint8_t *data, uint16_t len);
void ws_send_all(uint8_t *data, uint16_t len);
void ws_set_receive_handler( tWSHandler ws_handler);
void ws_set_open_handler( tWSOpenHandler ws_handler);