From e080117154e6ac442caefcb68719a809aef22a36 Mon Sep 17 00:00:00 2001 From: Luigi Cruz Date: Wed, 3 Mar 2021 23:48:48 -0300 Subject: [PATCH] Orgazine projects. --- CMakeLists.txt | 5 +-- apps/CMakeLists.txt | 2 + .../iperf_server}/CMakeLists.txt | 0 .../iperf_server}/lwipopts.h | 0 {iperf_server => apps/iperf_server}/main.c | 0 .../iperf_server}/tusb_config.h | 0 .../iperf_server}/usb_descriptors.c | 0 .../tcp_server}/CMakeLists.txt | 8 +++- {tcp_server => apps/tcp_server}/lwipopts.h | 0 {tcp_server => apps/tcp_server}/main.c | 38 +++++++++++++++++-- {tcp_server => apps/tcp_server}/tusb_config.h | 0 .../tcp_server}/usb_descriptors.c | 0 lib/CMakeLists.txt | 1 + {bmp180 => lib/bmp180}/CMakeLists.txt | 2 +- {bmp180 => lib/bmp180}/bmp180.h | 0 {bmp180 => lib/bmp180}/test.c | 0 16 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 apps/CMakeLists.txt rename {iperf_server => apps/iperf_server}/CMakeLists.txt (100%) rename {iperf_server => apps/iperf_server}/lwipopts.h (100%) rename {iperf_server => apps/iperf_server}/main.c (100%) rename {iperf_server => apps/iperf_server}/tusb_config.h (100%) rename {iperf_server => apps/iperf_server}/usb_descriptors.c (100%) rename {tcp_server => apps/tcp_server}/CMakeLists.txt (71%) rename {tcp_server => apps/tcp_server}/lwipopts.h (100%) rename {tcp_server => apps/tcp_server}/main.c (91%) rename {tcp_server => apps/tcp_server}/tusb_config.h (100%) rename {tcp_server => apps/tcp_server}/usb_descriptors.c (100%) create mode 100644 lib/CMakeLists.txt rename {bmp180 => lib/bmp180}/CMakeLists.txt (87%) rename {bmp180 => lib/bmp180}/bmp180.h (100%) rename {bmp180 => lib/bmp180}/test.c (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5e041e..e862a4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,5 @@ project(pico-stuff) pico_sdk_init() -add_subdirectory(bmp180) -add_subdirectory(iperf_server) -add_subdirectory(tcp_server) \ No newline at end of file +add_subdirectory(apps) +add_subdirectory(lib) \ No newline at end of file diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt new file mode 100644 index 0000000..b8da5aa --- /dev/null +++ b/apps/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(iperf_server) +add_subdirectory(tcp_server) \ No newline at end of file diff --git a/iperf_server/CMakeLists.txt b/apps/iperf_server/CMakeLists.txt similarity index 100% rename from iperf_server/CMakeLists.txt rename to apps/iperf_server/CMakeLists.txt diff --git a/iperf_server/lwipopts.h b/apps/iperf_server/lwipopts.h similarity index 100% rename from iperf_server/lwipopts.h rename to apps/iperf_server/lwipopts.h diff --git a/iperf_server/main.c b/apps/iperf_server/main.c similarity index 100% rename from iperf_server/main.c rename to apps/iperf_server/main.c diff --git a/iperf_server/tusb_config.h b/apps/iperf_server/tusb_config.h similarity index 100% rename from iperf_server/tusb_config.h rename to apps/iperf_server/tusb_config.h diff --git a/iperf_server/usb_descriptors.c b/apps/iperf_server/usb_descriptors.c similarity index 100% rename from iperf_server/usb_descriptors.c rename to apps/iperf_server/usb_descriptors.c diff --git a/tcp_server/CMakeLists.txt b/apps/tcp_server/CMakeLists.txt similarity index 71% rename from tcp_server/CMakeLists.txt rename to apps/tcp_server/CMakeLists.txt index e9449aa..1b31a26 100644 --- a/tcp_server/CMakeLists.txt +++ b/apps/tcp_server/CMakeLists.txt @@ -13,14 +13,18 @@ target_link_libraries(tcp_server tinyusb_host tinyusb_board tinyusb_net + hardware_i2c lwip ) -target_include_directories(tcp_server PRIVATE .) +target_include_directories(tcp_server PRIVATE + . + ${CMAKE_SOURCE_DIR}/lib/bmp180 +) pico_enable_stdio_usb(tcp_server 1) pico_enable_stdio_uart(tcp_server 0) pico_add_extra_outputs(tcp_server) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) \ No newline at end of file +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/tcp_server/lwipopts.h b/apps/tcp_server/lwipopts.h similarity index 100% rename from tcp_server/lwipopts.h rename to apps/tcp_server/lwipopts.h diff --git a/tcp_server/main.c b/apps/tcp_server/main.c similarity index 91% rename from tcp_server/main.c rename to apps/tcp_server/main.c index 0ec3f31..9d621cf 100644 --- a/tcp_server/main.c +++ b/apps/tcp_server/main.c @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2020 Peter Lawrence @@ -39,7 +39,7 @@ and likely their manufacturer has not tested such functionality. Some code work The smartphone may only have an ECM driver, but refuse to automatically pick ECM (unlike the OSes above); try modifying ./examples/devices/net_lwip_webserver/usb_descriptors.c so that CONFIG_ID_ECM is default. -The smartphone may be artificially picky about which Ethernet MAC address to recognize; if this happens, +The smartphone may be artificially picky about which Ethernet MAC address to recognize; if this happens, try changing the first byte of tud_network_mac_address[] below from 0x02 to 0x00 (clearing bit 1). */ @@ -50,9 +50,14 @@ try changing the first byte of tud_network_mac_address[] below from 0x02 to 0x00 #include "dnserver.h" #include "lwip/init.h" #include "lwip/timeouts.h" +#include "lwip/api.h" +#include "lwip/sys.h" +#include "lwip/udp.h" #include "httpd.h" +#include "bmp180.h" + /* lwip context */ static struct netif netif_data; @@ -155,7 +160,7 @@ bool dns_query_proc(const char *name, ip_addr_t *addr) bool tud_network_recv_cb(const uint8_t *src, uint16_t size) { - /* this shouldn't happen, but if we get another packet before + /* this shouldn't happen, but if we get another packet before parsing the previous, we must signal our inability to accept it */ if (received_frame) return false; @@ -220,6 +225,25 @@ void tud_network_init_cb(void) } } +bmp_t bmp; + +static void udpecho_raw_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port) +{ + if(p == NULL) + return; + + struct pbuf *pr; + uint8_t buf[4]; + + pr = pbuf_alloc(PBUF_TRANSPORT, 4, PBUF_POOL); + pr->len = 4; + pr->tot_len = 4; + pr->payload = buf; + + udp_sendto(pcb, pr, addr, port); + pbuf_free(p); +} + int main(void) { /* initialize TinyUSB */ @@ -231,6 +255,12 @@ int main(void) while (!netif_is_up(&netif_data)); while (dhserv_init(&dhcp_config) != ERR_OK); while (dnserv_init(&ipaddr, 53, dns_query_proc) != ERR_OK); + + struct udp_pcb *pcb; + pcb = udp_new(); + udp_bind(pcb, IP_ADDR_ANY, 7777); + udp_recv(pcb , udpecho_raw_recv, pcb); + httpd_init(); while (1) @@ -240,4 +270,4 @@ int main(void) } return 0; -} \ No newline at end of file +} diff --git a/tcp_server/tusb_config.h b/apps/tcp_server/tusb_config.h similarity index 100% rename from tcp_server/tusb_config.h rename to apps/tcp_server/tusb_config.h diff --git a/tcp_server/usb_descriptors.c b/apps/tcp_server/usb_descriptors.c similarity index 100% rename from tcp_server/usb_descriptors.c rename to apps/tcp_server/usb_descriptors.c diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 0000000..4e4c4c2 --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(bmp180) \ No newline at end of file diff --git a/bmp180/CMakeLists.txt b/lib/bmp180/CMakeLists.txt similarity index 87% rename from bmp180/CMakeLists.txt rename to lib/bmp180/CMakeLists.txt index dfb803b..4e0437b 100644 --- a/bmp180/CMakeLists.txt +++ b/lib/bmp180/CMakeLists.txt @@ -17,4 +17,4 @@ pico_enable_stdio_uart(bmp180 0) pico_add_extra_outputs(bmp180) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) \ No newline at end of file +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/bmp180/bmp180.h b/lib/bmp180/bmp180.h similarity index 100% rename from bmp180/bmp180.h rename to lib/bmp180/bmp180.h diff --git a/bmp180/test.c b/lib/bmp180/test.c similarity index 100% rename from bmp180/test.c rename to lib/bmp180/test.c