Add PHY hardware management for Bluetooth Coexistence pin choice
This commit is contained in:
parent
b61d06e940
commit
fd20b1a530
4 changed files with 109 additions and 4 deletions
32
core/esp_phy.c
Normal file
32
core/esp_phy.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/** esp/phy.h
|
||||
*
|
||||
* PHY hardware management functions.
|
||||
*
|
||||
* Part of esp-open-rtos
|
||||
* Copyright (C) 2016 ChefSteps, Inc
|
||||
* BSD Licensed as described in the file LICENSE
|
||||
*/
|
||||
#include <esp/phy.h>
|
||||
#include <esp/gpio.h>
|
||||
|
||||
void bt_coexist_configure(bt_coexist_mode_t mode, uint8_t bt_active_pin, uint8_t bt_priority_pin)
|
||||
{
|
||||
/* Disable coexistence entirely before changing pin assignments */
|
||||
GPIO.OUT &= ~(GPIO_OUT_BT_COEXIST_MASK);
|
||||
uint32_t new_mask = 0;
|
||||
|
||||
new_mask = VAL2FIELD_M(GPIO_OUT_BT_ACTIVE_PIN, bt_active_pin) +
|
||||
VAL2FIELD_M(GPIO_OUT_BT_PRIORITY_PIN, bt_priority_pin);
|
||||
|
||||
if(mode == BT_COEXIST_USE_BT_ACTIVE || mode == BT_COEXIST_USE_BT_ACTIVE_PRIORITY) {
|
||||
gpio_enable(bt_active_pin, GPIO_INPUT);
|
||||
new_mask |= GPIO_OUT_BT_ACTIVE_ENABLE;
|
||||
}
|
||||
if(mode == BT_COEXIST_USE_BT_ACTIVE_PRIORITY) {
|
||||
gpio_enable(bt_priority_pin, GPIO_INPUT);
|
||||
new_mask |= GPIO_OUT_BT_PRIORITY_ENABLE;
|
||||
}
|
||||
GPIO.OUT |= new_mask;
|
||||
}
|
||||
|
||||
|
|
@ -81,9 +81,9 @@ static inline void gpio_set_output_on_sleep(const uint8_t gpio_num, bool enabled
|
|||
static inline void gpio_write(const uint8_t gpio_num, const bool set)
|
||||
{
|
||||
if (set)
|
||||
GPIO.OUT_SET = BIT(gpio_num);
|
||||
GPIO.OUT_SET = BIT(gpio_num) & GPIO_OUT_PIN_MASK;
|
||||
else
|
||||
GPIO.OUT_CLEAR = BIT(gpio_num);
|
||||
GPIO.OUT_CLEAR = BIT(gpio_num) & GPIO_OUT_PIN_MASK;
|
||||
}
|
||||
|
||||
/* Toggle output of a pin
|
||||
|
@ -102,9 +102,9 @@ static inline void gpio_toggle(const uint8_t gpio_num)
|
|||
task's pins, without needing to disable/enable interrupts.
|
||||
*/
|
||||
if(GPIO.OUT & BIT(gpio_num))
|
||||
GPIO.OUT_CLEAR = BIT(gpio_num);
|
||||
GPIO.OUT_CLEAR = BIT(gpio_num) & GPIO_OUT_PIN_MASK;
|
||||
else
|
||||
GPIO.OUT_SET = BIT(gpio_num);
|
||||
GPIO.OUT_SET = BIT(gpio_num) & GPIO_OUT_PIN_MASK;
|
||||
}
|
||||
|
||||
/* Read input value of a GPIO pin.
|
||||
|
|
|
@ -61,6 +61,21 @@ struct GPIO_REGS {
|
|||
|
||||
_Static_assert(sizeof(struct GPIO_REGS) == 0x74, "GPIO_REGS is the wrong size");
|
||||
|
||||
/* Details for additional OUT register fields */
|
||||
|
||||
/* Bottom 16 bits of GPIO.OUT are for GPIOs 0-15, but upper 16 bits
|
||||
are used to configure the input signalling pins for Bluetooth
|
||||
Coexistence config (see esp/phy.h for a wrapper function).
|
||||
*/
|
||||
#define GPIO_OUT_PIN_MASK 0x0000FFFF
|
||||
#define GPIO_OUT_BT_COEXIST_MASK 0x03FF0000
|
||||
#define GPIO_OUT_BT_ACTIVE_ENABLE BIT(24)
|
||||
#define GPIO_OUT_BT_PRIORITY_ENABLE BIT(25)
|
||||
#define GPIO_OUT_BT_ACTIVE_PIN_M 0x0F
|
||||
#define GPIO_OUT_BT_ACTIVE_PIN_S 16
|
||||
#define GPIO_OUT_BT_PRIORITY_PIN_M 0x0F
|
||||
#define GPIO_OUT_BT_PRIORITY_PIN_S 20
|
||||
|
||||
/* Details for CONF[i] registers */
|
||||
|
||||
/* GPIO.CONF[i] control the pin behavior for the corresponding GPIO in/output.
|
||||
|
|
58
core/include/esp/phy.h
Normal file
58
core/include/esp/phy.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/** esp/phy.h
|
||||
*
|
||||
* PHY hardware management functions.
|
||||
*
|
||||
* These are not enough to configure the ESP8266 PHY by themselves
|
||||
* (yet), but they provide utilities to modify the configuration set
|
||||
* up via the SDK.
|
||||
*
|
||||
* Functions implemented here deal directly with the hardware, not the
|
||||
* SDK software layers.
|
||||
*
|
||||
* Part of esp-open-rtos
|
||||
* Copyright (C) 2016 ChefSteps, Inc
|
||||
* BSD Licensed as described in the file LICENSE
|
||||
*/
|
||||
#ifndef _ESP_PHY_H
|
||||
#define _ESP_PHY_H
|
||||
|
||||
#include <esp/types.h>
|
||||
#include <common_macros.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
BT_COEXIST_NONE,
|
||||
BT_COEXIST_USE_BT_ACTIVE,
|
||||
BT_COEXIST_USE_BT_ACTIVE_PRIORITY,
|
||||
} bt_coexist_mode_t;
|
||||
|
||||
/** Override the Bluetooth Coexistence BT_ACTIVE pin setting
|
||||
taken from the phy_info structure.
|
||||
|
||||
This enables other pins to be used for Bluetooth Coexistence
|
||||
signals (rather than just the two provided for by phy_info). (Note
|
||||
that not that not all pins are confirmed to work, GPIO 0 is
|
||||
confirmed not usable as the SDK configures it as the WLAN_ACTIVE
|
||||
output - even if you change the pin mode the SDK will change it
|
||||
back.)
|
||||
|
||||
To change pins and have coexistence work successfully the BT
|
||||
coexistence feature must be enabled in the phy_info configuration
|
||||
(get_default_phy_info()). You can then modify the initial
|
||||
configuration by calling this function from your own user_init
|
||||
function.
|
||||
|
||||
(Eventually we should be able to support enough PHY registers
|
||||
to enable coexistence without SDK support at all, but not yet.)
|
||||
|
||||
This function will enable bt_active_pin & bt_priority_as GPIO
|
||||
inputs, according to the mode parameter.
|
||||
|
||||
Remember that the default Bluetooth Coexistence pins will be
|
||||
configured as GPIOs by the SDK already, so you may want to
|
||||
reconfigure/re-iomux them after calling this function.
|
||||
*/
|
||||
void bt_coexist_configure(bt_coexist_mode_t mode, uint8_t bt_active_pin, uint8_t bt_priority_pin);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue