diff options
author | ThomasintAnker <thomasintanker1@gmail.com> | 2024-05-31 15:39:27 +0200 |
---|---|---|
committer | ThomasintAnker <thomasintanker1@gmail.com> | 2024-05-31 15:39:27 +0200 |
commit | 2107d89060c345906534f9b0a9eb37e679cdbce8 (patch) | |
tree | cad31babb26928d631fe6fd7a486e047b7ddba34 | |
parent | 0278037aaf3fd497aae57d90f2638ceda3b12a6d (diff) |
working coms between i2c and utp
-rw-r--r-- | main/i2c.c | 20 | ||||
-rw-r--r-- | main/main.c | 3 | ||||
-rw-r--r-- | main/sock.c | 25 |
3 files changed, 4 insertions, 44 deletions
@@ -7,11 +7,6 @@ #include <pico/stdlib.h> #include <hardware/i2c.h> -#include <FreeRTOS.h> -#include <queue.h> - -extern QueueHandle_t queue; - void init_i2c() { i2c_init(I2C_PORT, 100 * 1000); // currently at 100kHz @@ -94,21 +89,6 @@ void bus_task() { printf("Data: %d", data); } - // data = 0x01; - // // send data to found slave address - // write_i2c(found[i], &data, 1); - - // data = 0x02; - // write_i2c(found[i], &data, 1); - - // request update from slave addr at found[i] - //write_i2c(); - } - - uint8_t rcvData[2]; - if(xQueueReceive(queue, &rcvData, 5) == pdPASS){ - printf("Send to address: %d, datat: %d\n", rcvData[0], rcvData[1]); - write_i2c(rcvData[0], &rcvData[1], sizeof(rcvData[1])); } } } diff --git a/main/main.c b/main/main.c index 33912ec..051f500 100644 --- a/main/main.c +++ b/main/main.c @@ -1,5 +1,4 @@ #include <FreeRTOS.h> -#include <queue.h> #include <task.h> #include <pico/stdlib.h> @@ -10,8 +9,6 @@ #include "sock.h" #include "i2c.h" -QueueHandle_t queue; - void blink_task() { await_init(); // `blink_task` uses GPIO diff --git a/main/sock.c b/main/sock.c index 33da03c..0755a5d 100644 --- a/main/sock.c +++ b/main/sock.c @@ -5,13 +5,11 @@ #include <lwip/api.h> #include <string.h> -#include <FreeRTOS.h> -#include <queue.h> - #include "init.h" #include "config.h" #include "i2ctcpv1.h" #include "sock.h" +#include <hardware/i2c.h> extern QueueHandle_t queue; @@ -40,25 +38,12 @@ void i2c_send(uint16_t addr, const char * data, size_t data_size) { } void i2c_recv(uint16_t addr, const char * data, size_t data_size) { - /* - printf("address: 0x%02x\n", addr); - printf("data: \"%.*s\"\n", data_size, data); - - // send message back - char reply[] = "Test message back!"; - i2c_send(0x69, reply, strlen(reply)); - */ - // TODO: this function should forward the recieved message onto the puzzle // bus instead of printing/replying // using queueu -> i2c_write only accepts uint8_t addr, and uint8_t data ._. - printf("Sending data over i2c"); - uint8_t i2cData[2] = {addr, 0x00}; - if(xQueueSend(queue, &i2cData, portMAX_DELAY) == pdPASS) { - printf("Socket send data to address: %d, data: %d", i2cData[0], i2cData[1]); - } - + printf("Addr: %lu, Data: %c, Data_size: %lu\n", addr, data[0], data_size); + i2c_write_blocking(i2c0, addr, data, data_size, false); } void recv_handler(struct netconn* conn, struct netbuf* buf) { @@ -70,10 +55,8 @@ void recv_handler(struct netconn* conn, struct netbuf* buf) { netbuf_data(buf, (void**)&data, &len); // continue early if more data is needed to complete message - printf("yeetus deletus defeatus"); - if (!i2ctcp_read(&recv_msg, data, len)) continue; + if (i2ctcp_read(&recv_msg, data, len) > 0) continue; - printf("yeetus deletus defeatus v2!"); // forward received message to puzzle bus i2c_recv(recv_msg.addr, recv_msg.data, recv_msg.length); free(recv_msg.data); |