|
@@ -75,13 +75,6 @@ static struct lpc_spi lpc_obj[] =
|
|
#endif
|
|
#endif
|
|
};
|
|
};
|
|
|
|
|
|
-
|
|
|
|
-struct lpc_sw_spi_cs
|
|
|
|
-{
|
|
|
|
- rt_uint32_t pin;
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-
|
|
|
|
static uint32_t lpc_get_spi_freq(SPI_Type *base)
|
|
static uint32_t lpc_get_spi_freq(SPI_Type *base)
|
|
{
|
|
{
|
|
uint32_t freq = 0;
|
|
uint32_t freq = 0;
|
|
@@ -153,18 +146,13 @@ static rt_err_t lpc_spi_init(SPI_Type *base, struct rt_spi_configuration *cfg)
|
|
return RT_EOK;
|
|
return RT_EOK;
|
|
}
|
|
}
|
|
|
|
|
|
-rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_uint32_t pin)
|
|
|
|
|
|
+rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin)
|
|
{
|
|
{
|
|
rt_err_t ret = RT_EOK;
|
|
rt_err_t ret = RT_EOK;
|
|
|
|
|
|
struct rt_spi_device *spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
|
|
struct rt_spi_device *spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
|
|
- struct lpc_sw_spi_cs *cs_pin = (struct lpc_sw_spi_cs *)rt_malloc(sizeof(struct lpc_sw_spi_cs));
|
|
|
|
-
|
|
|
|
- cs_pin->pin = pin;
|
|
|
|
- rt_pin_mode(pin, PIN_MODE_OUTPUT);
|
|
|
|
- rt_pin_write(pin, PIN_HIGH);
|
|
|
|
|
|
|
|
- ret = rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin);
|
|
|
|
|
|
+ ret = rt_spi_bus_attach_device_cspin(spi_device, device_name, bus_name, cs_pin, RT_NULL);
|
|
|
|
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
@@ -174,8 +162,7 @@ rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name,
|
|
static rt_err_t spi_configure(struct rt_spi_device *device, struct rt_spi_configuration *cfg)
|
|
static rt_err_t spi_configure(struct rt_spi_device *device, struct rt_spi_configuration *cfg)
|
|
{
|
|
{
|
|
rt_err_t ret = RT_EOK;
|
|
rt_err_t ret = RT_EOK;
|
|
- struct lpc_spi *spi = RT_NULL;
|
|
|
|
- spi = (struct lpc_spi *)(device->bus->parent.user_data);
|
|
|
|
|
|
+ struct lpc_spi *spi = rt_container_of(device->bus, struct lpc_spi, parent);
|
|
ret = lpc_spi_init(spi->SPIx, cfg);
|
|
ret = lpc_spi_init(spi->SPIx, cfg);
|
|
|
|
|
|
return ret;
|
|
return ret;
|
|
@@ -195,15 +182,12 @@ static rt_ssize_t spixfer(struct rt_spi_device *device, struct rt_spi_message *m
|
|
|
|
|
|
RT_ASSERT(device != RT_NULL);
|
|
RT_ASSERT(device != RT_NULL);
|
|
RT_ASSERT(device->bus != RT_NULL);
|
|
RT_ASSERT(device->bus != RT_NULL);
|
|
- RT_ASSERT(device->bus->parent.user_data != RT_NULL);
|
|
|
|
-
|
|
|
|
|
|
|
|
- struct lpc_spi *spi = (struct lpc_spi *)(device->bus->parent.user_data);
|
|
|
|
- struct lpc_sw_spi_cs *cs = device->parent.user_data;
|
|
|
|
|
|
+ struct lpc_spi *spi = rt_container_of(device->bus, struct lpc_spi, parent);
|
|
|
|
|
|
- if(message->cs_take)
|
|
|
|
|
|
+ if(message->cs_take && (device->cs_pin != PIN_NONE))
|
|
{
|
|
{
|
|
- rt_pin_write(cs->pin, PIN_LOW);
|
|
|
|
|
|
+ rt_pin_write(device->cs_pin, PIN_LOW);
|
|
}
|
|
}
|
|
|
|
|
|
transfer.dataSize = message->length;
|
|
transfer.dataSize = message->length;
|
|
@@ -245,9 +229,9 @@ static rt_ssize_t spixfer(struct rt_spi_device *device, struct rt_spi_message *m
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- if(message->cs_release)
|
|
|
|
|
|
+ if(message->cs_release && (device->cs_pin != PIN_NONE))
|
|
{
|
|
{
|
|
- rt_pin_write(cs->pin, PIN_HIGH);
|
|
|
|
|
|
+ rt_pin_write(device->cs_pin, PIN_HIGH);
|
|
}
|
|
}
|
|
|
|
|
|
return message->length;
|
|
return message->length;
|