generated from LailaTheElf/rp2040_c
add driver for W5500
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +1,6 @@
|
||||
[submodule "libs/adafruitGFX"]
|
||||
path = libs/adafruitGFX
|
||||
url = https://git.gay/LailaTheElf/AdafruitGFX-RaspberryPICO.git
|
||||
[submodule "libs/wiznet/ioLibrary_Driver"]
|
||||
path = libs/wiznet/ioLibrary_Driver
|
||||
url = https://github.com/Wiznet/ioLibrary_Driver.git
|
||||
|
||||
@@ -9,23 +9,33 @@ project(temp_sensor)
|
||||
pico_sdk_init()
|
||||
|
||||
add_subdirectory(libs/adafruitGFX/AdafruitGFXPico)
|
||||
add_subdirectory(libs/wiznet)
|
||||
|
||||
add_executable(temp_sensor_debug
|
||||
src/main.cpp
|
||||
src/max31856.cpp
|
||||
)
|
||||
# add_executable(temp_sensor_debug
|
||||
# src/main.cpp
|
||||
# src/max31856.cpp
|
||||
# src/w5500_rp.cpp
|
||||
# )
|
||||
|
||||
target_link_libraries(temp_sensor_debug pico_stdlib hardware_spi AdafruitGFXPico)
|
||||
target_compile_options(temp_sensor_debug PRIVATE -Og)
|
||||
pico_enable_stdio_usb(temp_sensor_debug 1)
|
||||
pico_enable_stdio_uart(temp_sensor_debug 0)
|
||||
# target_link_libraries(temp_sensor_debug
|
||||
# pico_stdlib hardware_spi
|
||||
# AdafruitGFXPico
|
||||
# w5500_driver wiznet_dhcp wiznet_mqtt
|
||||
# )
|
||||
# target_compile_options(temp_sensor_debug PRIVATE -Og)
|
||||
# pico_enable_stdio_usb(temp_sensor_debug 1)
|
||||
# pico_enable_stdio_uart(temp_sensor_debug 0)
|
||||
|
||||
add_executable(temp_sensor
|
||||
src/main.cpp
|
||||
src/max31856.cpp
|
||||
src/w5500_rp.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(temp_sensor pico_stdlib hardware_spi AdafruitGFXPico)
|
||||
target_link_libraries(temp_sensor
|
||||
pico_stdlib hardware_spi
|
||||
AdafruitGFXPico
|
||||
w5500_driver wiznet_dhcp wiznet_mqtt)
|
||||
target_compile_options(temp_sensor PRIVATE -Ofast)
|
||||
pico_enable_stdio_usb(temp_sensor 1)
|
||||
pico_enable_stdio_uart(temp_sensor 0)
|
||||
|
||||
21
libs/wiznet/CMakeLists.txt
Normal file
21
libs/wiznet/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
add_library(w5500_driver
|
||||
ioLibrary_Driver/Ethernet/W5500/w5500.c
|
||||
ioLibrary_Driver/Ethernet/socket.c
|
||||
ioLibrary_Driver/Ethernet/wizchip_conf.c
|
||||
)
|
||||
target_include_directories(w5500_driver PUBLIC ./ioLibrary_Driver/Ethernet ./ioLibrary_Driver/Ethernet/W5500)
|
||||
target_compile_definitions(w5500_driver PUBLIC _WIZCHIP_=5500)
|
||||
|
||||
add_library(wiznet_dhcp
|
||||
ioLibrary_Driver/Internet/DHCP/dhcp.c
|
||||
)
|
||||
target_link_libraries(wiznet_dhcp w5500_driver)
|
||||
target_include_directories(wiznet_dhcp PUBLIC ./ioLibrary_Driver/Internet/DHCP)
|
||||
|
||||
add_library(wiznet_mqtt
|
||||
ioLibrary_Driver/Internet/MQTT/MQTTClient.c
|
||||
ioLibrary_Driver/Internet/MQTT/mqtt_interface.c
|
||||
)
|
||||
target_link_libraries(wiznet_mqtt w5500_driver)
|
||||
target_include_directories(wiznet_mqtt PUBLIC ./ioLibrary_Driver/Internet/DHCP)
|
||||
1
libs/wiznet/ioLibrary_Driver
Submodule
1
libs/wiznet/ioLibrary_Driver
Submodule
Submodule libs/wiznet/ioLibrary_Driver added at 1d2582a7d0
20
src/config.h
Normal file
20
src/config.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
// pin rgb led on Seeed XIAO RP2040
|
||||
#define PIN_RGB_R 17
|
||||
#define PIN_RGB_G 16
|
||||
#define PIN_RGB_B 25
|
||||
|
||||
#define PIN_SPI_CLK 2
|
||||
#define PIN_SPI_MISO 4
|
||||
#define PIN_SPI_MOSI 3
|
||||
#define PIN_MAX31856_CS 1
|
||||
#define PIN_DISPLAY_CS 0
|
||||
#define PIN_DISPLAY_DC 7
|
||||
#define PIN_DISPLAY_RST 6
|
||||
|
||||
#define PIN_W5500_CS 29
|
||||
#define W5500_SPI_DRIVER spi0
|
||||
|
||||
#endif
|
||||
25
src/main.cpp
25
src/main.cpp
@@ -6,20 +6,9 @@
|
||||
#include <Adafruit_SPIDevice.h>
|
||||
#include <Adafruit_ILI9341.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "max31856.h"
|
||||
|
||||
// pin rgb led on Seeed XIAO RP2040
|
||||
#define PIN_RGB_R 17
|
||||
#define PIN_RGB_G 16
|
||||
#define PIN_RGB_B 25
|
||||
|
||||
#define PIN_SPI_CLK 2
|
||||
#define PIN_SPI_MISO 4
|
||||
#define PIN_SPI_MOSI 3
|
||||
#define PIN_MAX31856_CS 1
|
||||
#define PIN_DISPLAY_CS 0
|
||||
#define PIN_DISPLAY_DC 7
|
||||
#define PIN_DISPLAY_RST 6
|
||||
#include "w5500_rp.h"
|
||||
|
||||
max31856_t temp[2];
|
||||
Adafruit_SPIDevice spidev(PIN_DISPLAY_CS, PIN_SPI_CLK, PIN_SPI_MISO, PIN_SPI_MOSI);
|
||||
@@ -55,16 +44,14 @@ int main() {
|
||||
stdio_init_all();
|
||||
init_rbg();
|
||||
|
||||
display.begin();
|
||||
|
||||
// init temp sensors
|
||||
temp[0].pin_cs = PIN_MAX31856_CS;
|
||||
max31856_init(&(temp[0]));
|
||||
//temp[1].pin_cs = 5;
|
||||
//max31856_init(&(temp[1]));
|
||||
gpio_set_function(PIN_SPI_CLK, GPIO_FUNC_SPI);
|
||||
gpio_set_function(PIN_SPI_MOSI, GPIO_FUNC_SPI);
|
||||
gpio_set_function(PIN_SPI_MISO, GPIO_FUNC_SPI);
|
||||
// temp[1].pin_cs = 5;
|
||||
//max31856_init(&(temp[1]));
|
||||
// config temp sensor 0
|
||||
max31856_write8(&(temp[0]), MAX31856_REG_CR0, MAX31856_REG_CR0_CMODE | /*MAX31856_REG_CR0_OCFAULT |*/ MAX31856_REG_CR0_50HZ);
|
||||
max31856_write8(&(temp[0]), MAX31856_REG_CR1, MAX31856_REG_CR1_AVGSEL_4 | MAX31856_REG_CR1_TC_TYPE_K);
|
||||
@@ -72,6 +59,10 @@ int main() {
|
||||
//max31856_write8(&(temp[1]), MAX31856_REG_CR0, MAX31856_REG_CR0_CMODE | /*MAX31856_REG_CR0_OCFAULT |*/ MAX31856_REG_CR0_50HZ);
|
||||
//max31856_write8(&(temp[1]), MAX31856_REG_CR1, MAX31856_REG_CR1_AVGSEL_1 | MAX31856_REG_CR1_TC_TYPE_K);
|
||||
|
||||
// init ethernet
|
||||
w5500_rp_init();
|
||||
|
||||
display.begin();
|
||||
display.fillScreen(SSD1306_BLACK);
|
||||
display.setTextColor(SSD1306_WHITE);
|
||||
display.setTextSize(2);
|
||||
|
||||
40
src/w5500_rp.cpp
Normal file
40
src/w5500_rp.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <wizchip_conf.h>
|
||||
#include "hardware/spi.h"
|
||||
#include <pico/stdlib.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "w5500_rp.h"
|
||||
|
||||
void w5500_rp_spi_write_byte(uint8_t byte) {
|
||||
spi_write_blocking(W5500_SPI_DRIVER, &byte, 1);
|
||||
}
|
||||
uint8_t w5500_rp_spi_read_byte() {
|
||||
uint8_t byte;
|
||||
spi_read_blocking(W5500_SPI_DRIVER, 0, &byte, 1);
|
||||
return byte;
|
||||
}
|
||||
|
||||
void w5500_rp_spi_write_burst(uint8_t *buffer, uint16_t size) {
|
||||
spi_write_blocking(W5500_SPI_DRIVER, buffer, size);
|
||||
}
|
||||
void w5500_rp_spi_read_burst(uint8_t *buffer, uint16_t size) {
|
||||
uint8_t byte;
|
||||
spi_read_blocking(W5500_SPI_DRIVER, 0, buffer, size);
|
||||
}
|
||||
|
||||
void w5500_rp_spi_cs_select() {
|
||||
gpio_put(PIN_W5500_CS, 0);
|
||||
}
|
||||
void w5500_rp_spi_cs_deselect() {
|
||||
gpio_put(PIN_W5500_CS, 1);
|
||||
}
|
||||
|
||||
void w5500_rp_init() {
|
||||
reg_wizchip_spi_cbfunc(&w5500_rp_spi_read_byte, &w5500_rp_spi_write_byte);
|
||||
reg_wizchip_spiburst_cbfunc(&w5500_rp_spi_read_burst, &w5500_rp_spi_write_burst);
|
||||
reg_wizchip_cs_cbfunc(w5500_rp_spi_cs_select, w5500_rp_spi_cs_deselect);
|
||||
reg_wizchip_cris_cbfunc(NULL, NULL);
|
||||
}
|
||||
8
src/w5500_rp.h
Normal file
8
src/w5500_rp.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef W5500_RP_H
|
||||
#define W5500_RP_H
|
||||
|
||||
#include "hardware/spi.h"
|
||||
|
||||
void w5500_rp_init();
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user