Merge branch 'iomux-set-func' of https://github.com/ourairquality/esp-open-rtos into ourairquality-iomux-set-func
Conflicts: core/include/esp/iomux.h
This commit is contained in:
commit
0875e5d55b
4 changed files with 24 additions and 24 deletions
|
@ -23,39 +23,34 @@
|
|||
#define _SPI1_SCK_GPIO 14
|
||||
#define _SPI1_CS0_GPIO 15
|
||||
|
||||
#define _SPI0_FUNC 1
|
||||
#define _SPI1_FUNC 2
|
||||
#define _SPI0_FUNC IOMUX_FUNC(1)
|
||||
#define _SPI1_FUNC IOMUX_FUNC(2)
|
||||
|
||||
#define _SPI_BUF_SIZE 64
|
||||
|
||||
static bool _minimal_pins[2] = {false, false};
|
||||
|
||||
inline static void _set_pin_function(uint8_t pin, uint32_t function)
|
||||
{
|
||||
iomux_set_function(gpio_to_iomux(pin), function);
|
||||
}
|
||||
|
||||
bool spi_init(uint8_t bus, spi_mode_t mode, uint32_t freq_divider, bool msb, spi_endianness_t endianness, bool minimal_pins)
|
||||
{
|
||||
switch (bus)
|
||||
{
|
||||
case 0:
|
||||
_set_pin_function(_SPI0_MISO_GPIO, _SPI0_FUNC);
|
||||
_set_pin_function(_SPI0_MOSI_GPIO, _SPI0_FUNC);
|
||||
_set_pin_function(_SPI0_SCK_GPIO, _SPI0_FUNC);
|
||||
gpio_set_iomux_function(_SPI0_MISO_GPIO, _SPI0_FUNC);
|
||||
gpio_set_iomux_function(_SPI0_MOSI_GPIO, _SPI0_FUNC);
|
||||
gpio_set_iomux_function(_SPI0_SCK_GPIO, _SPI0_FUNC);
|
||||
if (!minimal_pins)
|
||||
{
|
||||
_set_pin_function(_SPI0_HD_GPIO, _SPI0_FUNC);
|
||||
_set_pin_function(_SPI0_WP_GPIO, _SPI0_FUNC);
|
||||
_set_pin_function(_SPI0_CS0_GPIO, _SPI0_FUNC);
|
||||
gpio_set_iomux_function(_SPI0_HD_GPIO, _SPI0_FUNC);
|
||||
gpio_set_iomux_function(_SPI0_WP_GPIO, _SPI0_FUNC);
|
||||
gpio_set_iomux_function(_SPI0_CS0_GPIO, _SPI0_FUNC);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
_set_pin_function(_SPI1_MISO_GPIO, _SPI1_FUNC);
|
||||
_set_pin_function(_SPI1_MOSI_GPIO, _SPI1_FUNC);
|
||||
_set_pin_function(_SPI1_SCK_GPIO, _SPI1_FUNC);
|
||||
gpio_set_iomux_function(_SPI1_MISO_GPIO, _SPI1_FUNC);
|
||||
gpio_set_iomux_function(_SPI1_MOSI_GPIO, _SPI1_FUNC);
|
||||
gpio_set_iomux_function(_SPI1_SCK_GPIO, _SPI1_FUNC);
|
||||
if (!minimal_pins)
|
||||
_set_pin_function(_SPI1_CS0_GPIO, _SPI1_FUNC);
|
||||
gpio_set_iomux_function(_SPI1_CS0_GPIO, _SPI1_FUNC);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
|
|
|
@ -143,6 +143,16 @@ static inline gpio_inttype_t gpio_get_interrupt(const uint8_t gpio_num)
|
|||
return (gpio_inttype_t)FIELD2VAL(GPIO_CONF_INTTYPE, GPIO.CONF[gpio_num]);
|
||||
}
|
||||
|
||||
/* Set GPIO I/O Mux function.
|
||||
* The 'func' is an IOMUX_GPIO<n>_FUNC_<function> value, see iomux_regs.h
|
||||
*/
|
||||
inline static void gpio_set_iomux_function(const uint8_t gpio_num, uint32_t func)
|
||||
{
|
||||
uint8_t iomux_num = gpio_to_iomux(gpio_num);
|
||||
uint32_t prev = IOMUX.PIN[iomux_num] & ~IOMUX_PIN_FUNC_MASK;
|
||||
IOMUX.PIN[iomux_num] = func | prev;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -82,8 +82,8 @@ inline static void iomux_set_pullup_flags(uint8_t iomux_num, uint32_t pullup_fla
|
|||
inline static void iomux_set_gpio_function(uint8_t gpio_number, bool output_enable)
|
||||
{
|
||||
const uint8_t iomux_num = gpio_to_iomux(gpio_number);
|
||||
const uint32_t func = iomux_num > 11 ? 0 : 3;
|
||||
iomux_set_function(iomux_num, IOMUX_FUNC(func));
|
||||
const uint32_t func = iomux_num > 11 ? IOMUX_FUNC(0) : IOMUX_FUNC(3);
|
||||
iomux_set_function(iomux_num, func);
|
||||
iomux_set_direction_flags(iomux_num, output_enable ? IOMUX_PIN_OUTPUT_ENABLE : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,11 +47,6 @@ _Static_assert(sizeof(struct IOMUX_REGS) == 0x44, "IOMUX_REGS is the wrong size"
|
|||
/* WARNING: Macro evaluates argument twice */
|
||||
#define IOMUX_FUNC(val) (VAL2FIELD_M(IOMUX_PIN_FUNC_LOW, val) | VAL2FIELD_M(IOMUX_PIN_FUNC_HIGH, val))
|
||||
|
||||
/* WARNING: Macro evaluates argument twice */
|
||||
#define IOMUX_FUNC_VALUE(regbits) (FIELD2VAL(IOMUX_PIN_FUNC_LOW, regbits) | FIELD2VAL(IOMUX_PIN_FUNC_HIGH, regbits))
|
||||
|
||||
#define IOMUX_SET_FUNC(regbits, funcval) (((regbits) & ~IOMUX_PIN_FUNC_MASK) | (funcval))
|
||||
|
||||
#define IOMUX_GPIO0 IOMUX.PIN[12]
|
||||
#define IOMUX_GPIO1 IOMUX.PIN[5]
|
||||
#define IOMUX_GPIO2 IOMUX.PIN[13]
|
||||
|
|
Loading…
Reference in a new issue