82 lines
2.1 KiB
C
Raw Normal View History

#include <wizHelper.h>
#include <stdint.h>
#include <main2.h>
#include <spi.h>
2020-11-08 15:56:14 +01:00
#include <stdbool.h>
#include <logger.h>
#include <PontCoopScheduler.h>
#include <utils.h>
#include <wizchip_conf.h>
2020-11-08 15:56:14 +01:00
wiz_NetInfo wizNetInfo = {
.mac = { 0xa0, 0x57, 0x62, 0x01, 0x02, 0x03 },
.dhcp = NETINFO_DHCP
};
2020-11-08 16:22:25 +01:00
void wiz_cs_select(void) {
HAL_GPIO_WritePin(ETHER_CS_GPIO_Port, ETHER_CS_Pin, GPIO_PIN_RESET);
}
2020-11-08 16:22:25 +01:00
void wiz_cs_deselect(void) {
HAL_GPIO_WritePin(ETHER_CS_GPIO_Port, ETHER_CS_Pin, GPIO_PIN_SET);
}
2020-11-08 16:22:25 +01:00
uint8_t wiz_spi_readbyte(void) {
uint8_t rbuf;
HAL_SPI_Receive(&etherSpi, &rbuf, 1, HAL_MAX_DELAY);
return rbuf;
}
2020-11-08 16:22:25 +01:00
void wiz_spi_writebyte(uint8_t wb) {
HAL_SPI_Transmit(&etherSpi, &wb, 1, HAL_MAX_DELAY);
}
2020-11-08 16:22:25 +01:00
void wiz_spi_readburst(uint8_t* pBuf, uint16_t len) {
}
2020-11-08 16:22:25 +01:00
void wiz_spi_writeburst(uint8_t* pBuf, uint16_t len) {
2020-11-08 15:56:14 +01:00
}
static void wizReset(bool b) {
HAL_GPIO_WritePin(ETHER_RES_GPIO_Port, ETHER_RES_Pin, b ? GPIO_PIN_RESET : GPIO_PIN_SET);
}
static void wizDHCPHandler(void *handle) {
uint8_t phyLink = 0;
int8_t res = ctlwizchip(CW_GET_PHYLINK, (void*) &phyLink);
coloredMsg(LOG_RED, "wizdh, ctlwizchip returns %d, phy link is %d", res, phyLink);
}
int wizInit() {
coloredMsg(LOG_RED, "wizI, resetting Ethernet module");
wizReset(true);
activeDelay(2);
wizReset(false);
activeDelay(2);
2020-11-08 16:14:02 +01:00
coloredMsg(LOG_RED, "wizI, registering callbacks");
2020-11-08 16:22:25 +01:00
reg_wizchip_cs_cbfunc(wiz_cs_select, wiz_cs_deselect);
coloredMsg(LOG_GREEN, "wizI, cs funcs registed");
// reg_wizchip_spi_cbfunc(wiz_spi_readbyte, wiz_spi_writebyte);
// coloredMsg(LOG_GREEN, wizI, spi funcs registed");
2020-11-08 16:14:02 +01:00
// reg_wizchip_spiburst_cbfunc(void (*spi_rb)(uint8_t* pBuf, uint16_t len), void (*spi_wb)(uint8_t* pBuf, uint16_t len));
2020-11-08 15:56:14 +01:00
coloredMsg(LOG_RED, "wizI, initializing Ethernet module");
2020-11-08 16:19:50 +01:00
// int8_t res = wizchip_init(NULL, NULL);
// coloredMsg(LOG_RED, "wizI, module driver returned %d", res);
2020-11-08 15:56:14 +01:00
2020-11-08 16:03:13 +01:00
// wizchip_setnetinfo(&wizNetInfo);
// coloredMsg(LOG_RED, "wizI, netinfo set to Ethernet module");
2020-11-08 15:56:14 +01:00
2020-11-08 16:03:13 +01:00
// schAdd(wizDHCPHandler, NULL, 0, 1000);
// coloredMsg(LOG_RED, "wizI, DHCP handler scheduled");
2020-11-08 15:56:14 +01:00
return 0;
2020-11-08 16:03:13 +01:00
}