mirror of https://github.com/ARMmbed/mbed-os.git
Re-enabled SPI after adjusting HAL implementation to slightly different API.
parent
52b9563e56
commit
6c7d15d381
|
@ -1388,7 +1388,7 @@
|
||||||
"supported_form_factors": ["ARDUINO"],
|
"supported_form_factors": ["ARDUINO"],
|
||||||
"inherits": ["MCU_NRF51_32K"],
|
"inherits": ["MCU_NRF51_32K"],
|
||||||
"progen": {"target": "nrf51-dk"},
|
"progen": {"target": "nrf51-dk"},
|
||||||
"device_has": ["ERROR_PATTERN", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "SERIAL", "RTC", "SERIAL_ASYNCH", "SLEEP"]
|
"device_has": ["ERROR_PATTERN", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPI_ASYNCH"]
|
||||||
},
|
},
|
||||||
"NRF51_DK_BOOT": {
|
"NRF51_DK_BOOT": {
|
||||||
"supported_form_factors": ["ARDUINO"],
|
"supported_form_factors": ["ARDUINO"],
|
||||||
|
@ -1764,6 +1764,6 @@
|
||||||
"supported_form_factors": ["ARDUINO"],
|
"supported_form_factors": ["ARDUINO"],
|
||||||
"inherits": ["MCU_NRF52"],
|
"inherits": ["MCU_NRF52"],
|
||||||
"progen": {"target": "nrf52-dk"},
|
"progen": {"target": "nrf52-dk"},
|
||||||
"device_has": ["ERROR_PATTERN", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP"]
|
"device_has": ["ERROR_PATTERN", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPI_ASYNCH"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,16 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#include "mbed_assert.h"
|
|
||||||
#include "mbed_error.h"
|
|
||||||
#include "i2c_api.h"
|
#include "i2c_api.h"
|
||||||
#include "nrf_drv_twi.h"
|
|
||||||
#include "app_util_platform.h"
|
|
||||||
|
|
||||||
#if DEVICE_I2C
|
#if DEVICE_I2C
|
||||||
|
|
||||||
|
#include "mbed_assert.h"
|
||||||
|
#include "mbed_error.h"
|
||||||
|
#include "nrf_drv_twi.h"
|
||||||
|
#include "app_util_platform.h"
|
||||||
|
|
||||||
#if DEVICE_I2C_ASYNCH
|
#if DEVICE_I2C_ASYNCH
|
||||||
#define TWI_IDX(obj) ((obj)->i2c.twi_idx)
|
#define TWI_IDX(obj) ((obj)->i2c.twi_idx)
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -13,9 +13,11 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
//#include <math.h>
|
|
||||||
|
|
||||||
#include "spi_api.h"
|
#include "spi_api.h"
|
||||||
|
|
||||||
|
#if DEVICE_SPI
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "mbed_assert.h"
|
#include "mbed_assert.h"
|
||||||
|
@ -23,8 +25,6 @@
|
||||||
#include "nrf_drv_spi.h"
|
#include "nrf_drv_spi.h"
|
||||||
#include "app_util_platform.h"
|
#include "app_util_platform.h"
|
||||||
|
|
||||||
#if DEVICE_SPI
|
|
||||||
|
|
||||||
#define SPI_MESSAGE_SIZE 1
|
#define SPI_MESSAGE_SIZE 1
|
||||||
volatile uint8_t m_tx_buf[SPI_MESSAGE_SIZE] = {0};
|
volatile uint8_t m_tx_buf[SPI_MESSAGE_SIZE] = {0};
|
||||||
volatile uint8_t m_rx_buf[SPI_MESSAGE_SIZE] = {0};
|
volatile uint8_t m_rx_buf[SPI_MESSAGE_SIZE] = {0};
|
||||||
|
@ -55,11 +55,12 @@ static void master_event_handler(nrf_drv_spi_evt_t const * event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk)
|
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
|
||||||
{
|
{
|
||||||
m_config.sck_pin = sclk;
|
m_config.sck_pin = (uint8_t)sclk;
|
||||||
m_config.mosi_pin = mosi;
|
m_config.mosi_pin = (mosi != NC) ? (uint8_t)mosi : NRF_DRV_SPI_PIN_NOT_USED;
|
||||||
m_config.miso_pin = miso;
|
m_config.miso_pin = (miso != NC) ? (uint8_t)miso : NRF_DRV_SPI_PIN_NOT_USED;
|
||||||
|
m_config.ss_pin = (ssel != NC) ? (uint8_t)ssel : NRF_DRV_SPI_PIN_NOT_USED;
|
||||||
|
|
||||||
SPI_S(obj)->busy = false;
|
SPI_S(obj)->busy = false;
|
||||||
m_spi_struct = obj;
|
m_spi_struct = obj;
|
||||||
|
@ -122,13 +123,15 @@ static nrf_drv_spi_frequency_t freq_translate(int hz)
|
||||||
return frequency;
|
return frequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi_format(spi_t *obj, int bits, int mode, spi_bitorder_t order)
|
void spi_format(spi_t *obj, int bits, int mode, int slave)
|
||||||
{
|
{
|
||||||
if (bits != 8) {
|
if (bits != 8) {
|
||||||
error("Only 8bits SPI supported");
|
error("Only 8bits SPI supported");
|
||||||
}
|
}
|
||||||
|
if (slave != 0) {
|
||||||
|
error("SPI slave mode is not supported");
|
||||||
|
}
|
||||||
|
|
||||||
m_config.bit_order = ((order == SPI_MSB) ? NRF_DRV_SPI_BIT_ORDER_MSB_FIRST : NRF_DRV_SPI_BIT_ORDER_LSB_FIRST);
|
|
||||||
nrf_drv_spi_mode_t config_mode = mode_translate(mode);
|
nrf_drv_spi_mode_t config_mode = mode_translate(mode);
|
||||||
|
|
||||||
if (m_config.mode != config_mode) {
|
if (m_config.mode != config_mode) {
|
||||||
|
@ -182,14 +185,14 @@ void spi_slave_write(spi_t *obj, int value)
|
||||||
|
|
||||||
#if DEVICE_SPI_ASYNCH
|
#if DEVICE_SPI_ASYNCH
|
||||||
|
|
||||||
|
|
||||||
void spi_master_transfer(spi_t *obj,
|
void spi_master_transfer(spi_t *obj,
|
||||||
void *tx, size_t tx_length,
|
const void *tx, size_t tx_length,
|
||||||
void *rx, size_t rx_length,
|
void *rx, size_t rx_length, uint8_t bit_width,
|
||||||
uint32_t handler,
|
uint32_t handler, uint32_t event, DMAUsage hint)
|
||||||
uint32_t event,
|
|
||||||
DMAUsage hint)
|
|
||||||
{
|
{
|
||||||
|
(void)hint;
|
||||||
|
(void)bit_width;
|
||||||
|
|
||||||
m_user_handler = (user_handler_t)handler;
|
m_user_handler = (user_handler_t)handler;
|
||||||
m_event = event;
|
m_event = event;
|
||||||
|
|
||||||
|
@ -213,6 +216,7 @@ void spi_abort_asynch(spi_t *obj)
|
||||||
{
|
{
|
||||||
nrf_drv_spi_abort(SPI_DRV(obj));
|
nrf_drv_spi_abort(SPI_DRV(obj));
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
#endif // DEVICE_SPI_ASYNCH
|
||||||
|
|
||||||
#endif // DEVICE_SPI
|
#endif // DEVICE_SPI
|
||||||
|
|
Loading…
Reference in New Issue