changes from supporting Arduino Zero/SAMD21 HAL. take an opaque argument to I2C and SPI init() functions for pinmux.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/904ec76d Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/904ec76d Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/904ec76d Branch: refs/heads/sterly_refactor Commit: 904ec76d63883bbf19df0c55213bf2a4e76699a4 Parents: 425a213 Author: Sterling Hughes <[email protected]> Authored: Tue Aug 9 10:55:21 2016 -0700 Committer: Sterling Hughes <[email protected]> Committed: Tue Aug 9 10:55:21 2016 -0700 ---------------------------------------------------------------------- hw/hal/include/hal/hal_i2c.h | 8 +++----- hw/hal/include/hal/hal_spi.h | 5 ++++- hw/hal/include/hal/hal_uart.h | 9 +++++++++ hw/mcu/nordic/nrf52xxx/include/mcu/nrf52_hal.h | 7 ++++++- hw/mcu/nordic/nrf52xxx/src/hal_i2c.c | 18 +++++++++++++----- hw/mcu/nordic/nrf52xxx/src/hal_spi.c | 2 +- 6 files changed, 36 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/904ec76d/hw/hal/include/hal/hal_i2c.h ---------------------------------------------------------------------- diff --git a/hw/hal/include/hal/hal_i2c.h b/hw/hal/include/hal/hal_i2c.h index e8c02db..b7a35e3 100644 --- a/hw/hal/include/hal/hal_i2c.h +++ b/hw/hal/include/hal/hal_i2c.h @@ -69,14 +69,12 @@ struct hal_i2c_master_data { * Initialize a new i2c device with the I2C number. * * @param i2c_num The number of the I2C device being initialized - * @param scl_pin The GPIO pin to use for clock - * @param sda_pin The GPIO pin to use for data - * @param i2c_frequency The I2C frequency to use, in KHz + * @param cfg The hardware specific configuration structure to configure + * the I2C with. This includes things like pin configuration. * * @return 0 on success, and non-zero error code on failure */ -int hal_i2c_init(uint8_t i2c_num, int scl_pin, int sda_pin, - uint32_t i2c_frequency); +int hal_i2c_init(uint8_t i2c_num, void *cfg); /** * Sends a start condition and writes <len> bytes of data on the i2c. http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/904ec76d/hw/hal/include/hal/hal_spi.h ---------------------------------------------------------------------- diff --git a/hw/hal/include/hal/hal_spi.h b/hw/hal/include/hal/hal_spi.h index 7146a84..56d38a1 100644 --- a/hw/hal/include/hal/hal_spi.h +++ b/hw/hal/include/hal/hal_spi.h @@ -62,10 +62,13 @@ struct hal_spi_settings { * Initialize the SPI, given by spi_num. * * @param spi_num The number of the SPI to initialize + * @param cfg HW/MCU specific configuration, + * passed to the underlying + * implementation, providing extra configuration. * * @return 0 on success, non-zero error code on failure. */ -int hal_spi_init(uint8_t spi_num); +int hal_spi_init(uint8_t spi_num, void *cfg); /** * Configure the spi. http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/904ec76d/hw/hal/include/hal/hal_uart.h ---------------------------------------------------------------------- diff --git a/hw/hal/include/hal/hal_uart.h b/hw/hal/include/hal/hal_uart.h index 1233727..dc83dca 100644 --- a/hw/hal/include/hal/hal_uart.h +++ b/hw/hal/include/hal/hal_uart.h @@ -69,6 +69,15 @@ enum hal_uart_flow_ctl { }; /** + * Initialize the HAL uart. + * + * @param uart The uart number to configure + * @param cfg Hardware specific uart configuration. This is passed from BSP + * directly to the MCU specific driver. + */ +int hal_uart_init(int uart, void *cfg); + +/** * hal uart config * * Applies given configuration to UART. http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/904ec76d/hw/mcu/nordic/nrf52xxx/include/mcu/nrf52_hal.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/nrf52xxx/include/mcu/nrf52_hal.h b/hw/mcu/nordic/nrf52xxx/include/mcu/nrf52_hal.h index 45891d9..048e0a0 100755 --- a/hw/mcu/nordic/nrf52xxx/include/mcu/nrf52_hal.h +++ b/hw/mcu/nordic/nrf52xxx/include/mcu/nrf52_hal.h @@ -6,7 +6,7 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, @@ -46,6 +46,11 @@ struct nrf52_uart_cfg { }; const struct nrf52_uart_cfg *bsp_uart_config(void); +struct nrf52_hal_i2c_cfg { + int scl_pin; + int sda_pin; + uint32_t i2c_frequency; +}; struct hal_flash; extern const struct hal_flash nrf52k_flash_dev; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/904ec76d/hw/mcu/nordic/nrf52xxx/src/hal_i2c.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_i2c.c b/hw/mcu/nordic/nrf52xxx/src/hal_i2c.c index 17b841d..1394d81 100644 --- a/hw/mcu/nordic/nrf52xxx/src/hal_i2c.c +++ b/hw/mcu/nordic/nrf52xxx/src/hal_i2c.c @@ -25,6 +25,10 @@ #include <nrf.h> #include <nrf_drv_twi.h> +#include <mcu/nrf52_hal.h> + +#include <assert.h> + struct nrf52_hal_i2c { nrf_drv_twi_t nhi_nrf_master; }; @@ -63,18 +67,22 @@ struct nrf52_hal_i2c *nrf52_hal_i2cs[NRF52_HAL_I2C_MAX] = { } int -hal_i2c_init(uint8_t i2c_num, int scl_pin, int sda_pin, - uint32_t i2c_frequency) +hal_i2c_init(uint8_t i2c_num, void *usercfg) { struct nrf52_hal_i2c *i2c; + struct nrf52_hal_i2c_cfg *i2c_cfg; nrf_drv_twi_config_t cfg; int rc; + assert(usercfg != NULL); + NRF52_HAL_I2C_RESOLVE(i2c_num, i2c); - cfg.scl = scl_pin; - cfg.sda = sda_pin; - switch (i2c_frequency) { + i2c_cfg = (struct nrf52_hal_i2c_cfg *) usercfg; + + cfg.scl = i2c_cfg->scl_pin; + cfg.sda = i2c_cfg->sda_pin; + switch (i2c_cfg->i2c_frequency) { case 100: cfg.frequency = NRF_TWI_FREQ_100K; break; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/904ec76d/hw/mcu/nordic/nrf52xxx/src/hal_spi.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_spi.c b/hw/mcu/nordic/nrf52xxx/src/hal_spi.c index f12c5f3..c8f9e57 100644 --- a/hw/mcu/nordic/nrf52xxx/src/hal_spi.c +++ b/hw/mcu/nordic/nrf52xxx/src/hal_spi.c @@ -75,7 +75,7 @@ nrf_drv_spi_config_t cfg_spi1 = NRF_DRV_SPI_DEFAULT_CONFIG(1); } int -hal_spi_init(uint8_t spi_num) +hal_spi_init(uint8_t spi_num, void *cfg) { return (0); }
