Skip to content

Commit 1bad6c7

Browse files
authored
Add files via upload
1 parent 06063dc commit 1bad6c7

File tree

84 files changed

+4327
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+4327
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2024 Serialcomms (GitHub).
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#include <stdio.h>
8+
#include "pico/stdlib.h"
9+
#include "include/USB_vcp.h"
10+
#include "API_usb_serial.h"
11+
#include "include/USB_initialise.h"
12+
#include "include/USB_com_port_signalling.h"
13+
14+
void usb_start_serial(bool set_cr_lf, bool set_exclusive) {
15+
16+
usb_device_init();
17+
18+
usb_insert_device();
19+
20+
busy_wait_ms(333);
21+
22+
init_usb_vcp_serial(set_cr_lf, set_exclusive);
23+
24+
}
25+
26+
void usb_stop_serial() {
27+
28+
stdio_set_chars_available_callback(NULL, NULL);
29+
30+
stdio_set_driver_enabled(&virtual_com_port, false);
31+
32+
usb_remove_device();
33+
34+
}
35+
36+
void set_com_port_dcd(bool dcd_state) {
37+
38+
com_port_set_dcd(dcd_state);
39+
40+
}
41+
42+
void set_com_port_dsr(bool dsr_state) {
43+
44+
com_port_set_dsr(dsr_state);
45+
46+
}
47+
48+
void set_com_port_ring(bool ring_state) {
49+
50+
com_port_set_ring(ring_state);
51+
52+
}
53+
54+
bool get_com_port_dtr() {
55+
56+
return com_port_get_dtr();
57+
58+
}
59+
60+
bool get_com_port_rts() {
61+
62+
return com_port_get_rts();
63+
64+
}
65+
66+
bool get_cdc_configuration_set() {
67+
68+
return CDC_CONFIGURATION_SET;
69+
70+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2024 Serialcomms (GitHub).
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#include "pico/stdlib.h"
8+
9+
extern bool CDC_CONFIGURATION_SET;
10+
11+
void usb_start_serial(bool set_cr_lf, bool set_exclusive);
12+
void usb_stop_serial();
13+
14+
void set_com_port_dcd(bool dcd_state);
15+
void set_com_port_dsr(bool dsr_state);
16+
void set_com_port_ring(bool ring_state);
17+
18+
bool get_com_port_dtr();
19+
bool get_com_port_rts();
20+
21+
bool get_cdc_configuration_set();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
add_library(lib_usb_cdc_serial INTERFACE)
2+
3+
target_sources(lib_usb_cdc_serial INTERFACE
4+
5+
API_usb_serial.c
6+
USB_EP0_handlers.c
7+
USB_EP1_handlers.c
8+
USB_EP2_handlers.c
9+
USB_buffer_completion.c
10+
USB_buffer_control.c
11+
USB_build_endpoints.c
12+
USB_bus_reset.c
13+
USB_cdc_line_coding.c
14+
USB_cdc_line_control.c
15+
USB_com_port_framing.c
16+
USB_com_port_signalling.c
17+
USB_data_packet.c
18+
USB_descriptor_config.c
19+
USB_descriptor_device.c
20+
USB_endpoints_host.c
21+
USB_endpoints_pico.c
22+
USB_error.c
23+
USB_initialise.c
24+
USB_interrupts.c
25+
USB_queue_control.c
26+
USB_queue_receive.c
27+
USB_queue_transmit.c
28+
USB_set_configuration.c
29+
USB_setup_address.c
30+
USB_setup_class_cdc.c
31+
USB_setup_control.c
32+
USB_setup_descriptors.c
33+
USB_setup_device.c
34+
USB_setup_endpoint.c
35+
USB_setup_interface.c
36+
USB_setup_packet.c
37+
USB_setup_strings.c
38+
USB_setup_type_class.c
39+
USB_setup_type_standard.c
40+
USB_sie_errors.c
41+
USB_sie_status.c
42+
USB_vcp.c
43+
# debug version only below
44+
USB_uart_printf.c
45+
USB_setup_show.c
46+
USB_debug_show.c
47+
)
48+
49+
message("--------------------------------------------------------------")
50+
message("-- Building serialcomms library lib_usb_cdc_serial (debug) ")
51+
message("--------------------------------------------------------------")
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright (c) 2024 Serialcomms (GitHub).
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
#include <stdio.h>
7+
#include "pico/stdlib.h"
8+
#include "pico/util/queue.h"
9+
#include "hardware/structs/usb.h"
10+
#include "include/USB_buffer_control.h"
11+
#include "include/USB_endpoints_pico.h"
12+
#include "include/USB_EP0_handlers.h"
13+
#include "include/USB_data_packet.h"
14+
#include "include/USB_setup_control.h"
15+
#include "include/USB_queue_control.h"
16+
#include "include/USB_queue_receive.h"
17+
#include "include/USB_queue_transmit.h"
18+
#include "include/USB_endpoint_struct.h"
19+
#include "include/USB_debug_show.h"
20+
#include "include/USB_uart_printf.h"
21+
22+
void ep0_handler_to_host(uint8_t EP_NUMBER) {
23+
24+
clear_buffer_status(USB_BUFF_STATUS_EP0_IN_BITS);
25+
26+
toggle_next_data_pid_to_host(0);
27+
28+
uint16_t bytes_remaining = get_queue_level_to_host(0);
29+
30+
uart_printf("EP%d handler to Host, clearing buffer status, buffer bytes=%d, queue bytes=%d, last PID=%d\n\r",
31+
0, get_buffer_control_transfer_bytes_to_host(0), get_queue_level_to_host(0), get_last_data_pid_to_host(0));
32+
33+
if (bytes_remaining) {
34+
35+
ep0_queue_runner_to_host();
36+
37+
} else {
38+
39+
end_pico_to_host_control_transfer();
40+
41+
}
42+
43+
}
44+
45+
static inline void ep0_queue_runner_to_host() {
46+
47+
bool queue_remove_result;
48+
uint8_t source_data_byte;
49+
uint16_t source_data_offset = 0;
50+
uint8_t *endpoint_buffer = host_endpoint[0].dpram_address;
51+
52+
uart_printf("%s Queue Length = %d\n\r", __func__, queue_get_level(&host_endpoint[0].data_queue));
53+
54+
do {
55+
56+
queue_remove_result = queue_try_remove_to_host(0, &source_data_byte);
57+
58+
if (queue_remove_result) endpoint_buffer[source_data_offset++] = source_data_byte;
59+
60+
} while (queue_remove_result && source_data_offset < host_endpoint[0].max_packet_size);
61+
62+
uart_printf("Continue Queued Transfer, data count = %d\n\r", source_data_offset);
63+
64+
if (source_data_offset) start_async_send_data_packet(0, source_data_offset);
65+
66+
}
67+
68+
// ---------------------------------------------------------------------------------------------------------
69+
70+
void ep0_handler_to_pico(uint8_t EP_NUMBER) {
71+
72+
clear_buffer_status(USB_BUFF_STATUS_EP0_OUT_BITS);
73+
74+
toggle_next_data_pid_to_pico(0);
75+
76+
pico_endpoint[0].transfer_bytes = get_buffer_control_transfer_bytes_to_pico(0);
77+
78+
uart_printf("EP%d handler to Pico, clearing buffer status, buffer bytes=%d, queue level=%d, last PID=%d\n\r",
79+
0,
80+
get_buffer_control_transfer_bytes_to_pico(0),
81+
get_queue_level_to_pico(0),
82+
get_last_data_pid_to_pico(0));
83+
84+
show_dpram_ep0();
85+
86+
if (get_pico_callback_handler(0)) run_pico_callback_handler();
87+
88+
}
89+
90+
static inline void run_pico_callback_handler() {
91+
92+
uart_printf("Buffer Status, special case for EP0 CDC control transfer data, callback=%08X \n\r", pico_endpoint[0].callback_handler);
93+
94+
void* buffer = pico_endpoint[0].dpram_address;
95+
96+
uint16_t transfer_bytes = pico_endpoint[0].transfer_bytes;
97+
98+
endpoint_callback_handler pico_callback = get_pico_callback_handler(0);
99+
100+
pico_callback(buffer, transfer_bytes);
101+
102+
set_pico_callback_handler(0, NULL);
103+
104+
}
105+
106+
static inline void clear_buffer_status (uint32_t buffer_mask) {
107+
108+
usb_hardware_clear->buf_status = buffer_mask;
109+
110+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2024 Serialcomms (GitHub).
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#include <stdio.h>
8+
#include "pico/stdlib.h"
9+
10+
#include "hardware/structs/usb.h" // USB hardware struct definitions
11+
#include "include/USB_endpoint_struct.h"
12+
#include "include/USB_queue_transmit.h"
13+
#include "include/USB_buffer_control.h"
14+
#include "include/USB_queue_control.h"
15+
#include "include/USB_EP1_handlers.h"
16+
#include "include/USB_uart_printf.h"
17+
18+
void ep1_handler_to_host () {
19+
20+
clear_buffer_status(USB_BUFF_STATUS_EP1_IN_BITS);
21+
22+
toggle_next_data_pid_to_host(1);
23+
24+
set_queue_busy_to_host(1, false);
25+
26+
uart_printf("EP1 handler to Host, clearing buffer status\n\r");
27+
28+
}
29+
30+
static inline void clear_buffer_status (uint32_t buffer_mask) {
31+
32+
usb_hardware_clear->buf_status = buffer_mask;
33+
34+
}

0 commit comments

Comments
 (0)