Skip to content

Commit db6e51c

Browse files
committed
pbio/platform/ev3: Pins for ev3 bluetooth module.
This adds the CTS and RTS pin definitions for UART2. It also configures the "slow clock" input for the bluetooth module. Configures the BTnShutdn gpio. Enables the ECAP functions in the PSC.
1 parent a6fcf10 commit db6e51c

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

lib/pbio/platform/ev3/platform.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <tiam1808/hw/hw_syscfg1_AM1808.h>
4949
#include <tiam1808/hw/hw_types.h>
5050
#include <tiam1808/hw/soc_AM1808.h>
51+
#include <tiam1808/ecap.h>
5152
#include <tiam1808/i2c.h>
5253
#include <tiam1808/psc.h>
5354
#include <tiam1808/timer.h>
@@ -784,8 +785,8 @@ void SystemInit(void) {
784785
IntChannelSet(SYS_INT_CCERRINT, 2);
785786
IntSystemEnable(SYS_INT_CCERRINT);
786787

787-
788788
PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);
789+
PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_ECAP0_1_2, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);
789790

790791
// Must set the power enable bin before disabling the pull up on the power
791792
// pin below, otherwise the hub will power off.
@@ -795,11 +796,41 @@ void SystemInit(void) {
795796
HWREG(SOC_SYSCFG_1_REGS + SYSCFG1_PUPD_ENA) &= ~0xFFFFFFFF;
796797

797798
// UART for Bluetooth. Other UARTS are configured by port module.
798-
// TODO: Add CTS/RTS pins.
799799
const pbdrv_gpio_t bluetooth_uart_rx = PBDRV_GPIO_EV3_PIN(4, 19, 16, 1, 3);
800800
const pbdrv_gpio_t bluetooth_uart_tx = PBDRV_GPIO_EV3_PIN(4, 23, 20, 1, 2);
801+
const pbdrv_gpio_t bluetooth_uart_cts = PBDRV_GPIO_EV3_PIN(0, 31, 28, 0, 8);
802+
const pbdrv_gpio_t bluetooth_uart_rts = PBDRV_GPIO_EV3_PIN(0, 27, 24, 0, 9);
803+
const pbdrv_gpio_t bluetooth_enable = PBDRV_GPIO_EV3_PIN(9, 27, 24, 4, 9);
801804
pbdrv_gpio_alt(&bluetooth_uart_rx, SYSCFG_PINMUX4_PINMUX4_19_16_UART2_RXD);
802805
pbdrv_gpio_alt(&bluetooth_uart_tx, SYSCFG_PINMUX4_PINMUX4_23_20_UART2_TXD);
806+
pbdrv_gpio_alt(&bluetooth_uart_cts, SYSCFG_PINMUX0_PINMUX0_31_28_UART2_CTS);
807+
pbdrv_gpio_alt(&bluetooth_uart_rts, SYSCFG_PINMUX0_PINMUX0_27_24_UART2_RTS);
808+
pbdrv_gpio_alt(&bluetooth_enable, SYSCFG_PINMUX4_PINMUX4_27_24_GPIO1_1);
809+
// For power saving, the bluetooth module disabled until its use is
810+
// requested.
811+
pbdrv_gpio_out_low(&bluetooth_enable);
812+
813+
// Configure ECAP2 to emit the slow clock signal for the bluetooth module.
814+
ECAPOperatingModeSelect(SOC_ECAP_2_REGS, ECAP_APWM_MODE);
815+
// Calculate the number of clock ticks the APWM period should last. Note
816+
// that the following float operations are all constant and optimized away.
817+
// APWM is clocked by sysclk2 by default.
818+
// Target frequency is 32.767 kHz, see cc2560 datasheet.
819+
const float period_cycles = SOC_SYSCLK_2_FREQ / 32767.0;
820+
// APWM counter counts up to aprd inclusive.
821+
const int aprd = period_cycles - 1;
822+
const int cmp = aprd / 2;
823+
ECAPAPWMCaptureConfig(SOC_ECAP_2_REGS, cmp, aprd);
824+
// Set the polarity to active high. It doesn't matter which it is but for
825+
// the sake of determinism we set it explicitly.
826+
ECAPAPWMPolarityConfig(SOC_ECAP_2_REGS, ECAP_APWM_ACTIVE_HIGH);
827+
// Disable input and output synchronization.
828+
ECAPSyncInOutSelect(SOC_ECAP_2_REGS, ECAP_SYNC_IN_DISABLE, ECAP_SYNC_OUT_DISABLE);
829+
// Start the counter running.
830+
ECAPCounterControl(SOC_ECAP_2_REGS, ECAP_COUNTER_FREE_RUNNING);
831+
// Set gp0[7] to output the ECAP2 APWM signal.
832+
const pbdrv_gpio_t bluetooth_slow_clock = PBDRV_GPIO_EV3_PIN(1, 3, 0, 0, 7);
833+
pbdrv_gpio_alt(&bluetooth_slow_clock, SYSCFG_PINMUX1_PINMUX1_3_0_ECAP2);
803834

804835
// Read the EV3 Bluetooth MAC address from the I2C boot EEPROM
805836

0 commit comments

Comments
 (0)