refactor: remove CH390 bitbang read path and sync manuals
This commit is contained in:
@@ -61,8 +61,6 @@ extern SPI_HandleTypeDef hspi1;
|
||||
/* Timeout for SPI operations (ms) */
|
||||
#define SPI_TIMEOUT 100
|
||||
|
||||
#define CH390_BITBANG_HALF_PERIOD_US 2u
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Low-level GPIO operations
|
||||
*---------------------------------------------------------------------------*/
|
||||
@@ -105,63 +103,6 @@ static inline uint8_t ch390_miso(void)
|
||||
return (uint8_t)(HAL_GPIO_ReadPin(CH390_MISO_PORT, CH390_MISO_PIN) == GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
static void ch390_spi_gpio_mode(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
GPIO_InitStruct.Pin = CH390_SCK_PIN | CH390_MOSI_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(CH390_SCK_PORT, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = CH390_MISO_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(CH390_MISO_PORT, &GPIO_InitStruct);
|
||||
|
||||
ch390_cs(1u);
|
||||
ch390_sck(1u);
|
||||
ch390_mosi(1u);
|
||||
}
|
||||
|
||||
static void ch390_spi_restore_pins(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
GPIO_InitStruct.Pin = CH390_SCK_PIN | CH390_MOSI_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(CH390_SCK_PORT, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = CH390_MISO_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(CH390_MISO_PORT, &GPIO_InitStruct);
|
||||
|
||||
ch390_spi_init();
|
||||
}
|
||||
|
||||
static uint8_t ch390_bitbang_exchange_byte(uint8_t byte)
|
||||
{
|
||||
uint8_t bit;
|
||||
uint8_t rx_data = 0u;
|
||||
|
||||
for (bit = 0u; bit < 8u; ++bit) {
|
||||
ch390_mosi((uint8_t)((byte & 0x80u) != 0u));
|
||||
ch390_delay_us(CH390_BITBANG_HALF_PERIOD_US);
|
||||
ch390_sck(0u);
|
||||
ch390_delay_us(CH390_BITBANG_HALF_PERIOD_US);
|
||||
rx_data = (uint8_t)((rx_data << 1) | ch390_miso());
|
||||
ch390_sck(1u);
|
||||
byte <<= 1;
|
||||
ch390_delay_us(CH390_BITBANG_HALF_PERIOD_US);
|
||||
}
|
||||
|
||||
return rx_data;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* SPI Communication
|
||||
*---------------------------------------------------------------------------*/
|
||||
@@ -260,7 +201,7 @@ void ch390_spi_init(void)
|
||||
/* - CPOL = High (idle clock is high) */
|
||||
/* - CPHA = 2Edge (data captured on second edge) */
|
||||
|
||||
ch390_spi_apply_mode(SPI_POLARITY_HIGH, SPI_PHASE_2EDGE);
|
||||
ch390_spi_apply_mode(SPI_POLARITY_LOW, SPI_PHASE_1EDGE); /* Start with Mode 0 */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -311,28 +252,13 @@ void ch390_delay_us(uint32_t time)
|
||||
*/
|
||||
void ch390_hardware_reset(void)
|
||||
{
|
||||
ch390_delay_us(3000); /* Short delay before reset */
|
||||
ch390_rst(0); /* Assert reset (low) */
|
||||
ch390_delay_us(1000); /* Hold reset for 1ms to satisfy datasheet minimum */
|
||||
ch390_delay_us(3000); /* Hold reset for 3ms to satisfy datasheet minimum */
|
||||
ch390_rst(1); /* Release reset (high) */
|
||||
ch390_delay_us(50000); /* Wait 50ms for CH390 to initialize reliably */
|
||||
}
|
||||
|
||||
uint8_t ch390_bitbang_read_reg(uint8_t reg)
|
||||
{
|
||||
uint8_t value;
|
||||
|
||||
__HAL_SPI_DISABLE(&hspi1);
|
||||
ch390_spi_gpio_mode();
|
||||
|
||||
ch390_cs(0u);
|
||||
(void)ch390_bitbang_exchange_byte((uint8_t)(reg | OPC_REG_R));
|
||||
value = ch390_bitbang_exchange_byte(0x00u);
|
||||
ch390_cs(1u);
|
||||
|
||||
ch390_spi_restore_pins();
|
||||
return value;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* CH390 Register/Memory Access Functions (SPI Mode)
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
@@ -19,7 +19,6 @@ void ch390_spi_init(void);
|
||||
uint16_t ch390_get_int_pin(void);
|
||||
void ch390_delay_us(uint32_t time);
|
||||
void ch390_hardware_reset(void);
|
||||
uint8_t ch390_bitbang_read_reg(uint8_t reg);
|
||||
|
||||
/**
|
||||
* @name ch390_read_reg
|
||||
|
||||
@@ -123,13 +123,6 @@ void ch390_runtime_init(struct netif *netif, const uint8_t *mac)
|
||||
SEGGER_RTT_WriteString(0, "ETH init: probe\r\n");
|
||||
g_ch390_ready = ch390_runtime_probe_identity();
|
||||
if (g_ch390_ready == 0u) {
|
||||
SEGGER_RTT_printf(0,
|
||||
"CH390 bitbang VIDL=0x%02X VIDH=0x%02X PIDL=0x%02X PIDH=0x%02X CHIPR=0x%02X\r\n",
|
||||
ch390_bitbang_read_reg(CH390_VIDL),
|
||||
ch390_bitbang_read_reg(CH390_VIDH),
|
||||
ch390_bitbang_read_reg(CH390_PIDL),
|
||||
ch390_bitbang_read_reg(CH390_PIDH),
|
||||
ch390_bitbang_read_reg(CH390_CHIPR));
|
||||
netif->hwaddr_len = ETHARP_HWADDR_LEN;
|
||||
netif->mtu = 1500;
|
||||
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;
|
||||
|
||||
Reference in New Issue
Block a user