Import of the watch repository from Pebble

This commit is contained in:
Matthieu Jeanson 2024-12-12 16:43:03 -08:00 committed by Katharine Berry
commit 3b92768480
10334 changed files with 2564465 additions and 0 deletions

View file

@ -0,0 +1,270 @@
/*
* Copyright 2024 Google LLC
*
* Licensed 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, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "drivers/button_id.h"
#if defined(MICRO_FAMILY_STM32F2)
#include "stm32f2xx_gpio.h"
#elif defined(MICRO_FAMILY_STM32F4)
#include "stm32f4xx_gpio.h"
#endif
#include <stdint.h>
#include <stdbool.h>
#define GPIO_Port_NULL ((GPIO_TypeDef *) 0)
#define GPIO_Pin_NULL ((uint16_t)0x0000)
typedef struct {
//! One of EXTI_PortSourceGPIOX
uint8_t exti_port_source;
//! Value between 0-15
uint8_t exti_line;
} ExtiConfig;
typedef struct {
const char* const name; ///< Name for debugging purposes.
GPIO_TypeDef* const gpio; ///< One of GPIOX. For example, GPIOA.
const uint32_t gpio_pin; ///< One of GPIO_Pin_X.
ExtiConfig exti;
GPIOPuPd_TypeDef pull;
} ButtonConfig;
typedef struct {
GPIO_TypeDef* const gpio; ///< One of GPIOX. For example, GPIOA.
const uint32_t gpio_pin; ///< One of GPIO_Pin_X.
} ButtonComConfig;
typedef struct {
GPIO_TypeDef* const gpio; ///< One of GPIOX. For example, GPIOA.
const uint32_t gpio_pin; ///< One of GPIO_Pin_X.
} InputConfig;
typedef struct {
GPIO_TypeDef* const gpio; ///< One of GPIOX. For example, GPIOA.
const uint16_t gpio_pin; ///< One of GPIO_Pin_*
const uint8_t adc_channel; ///< One of ADC_Channel_*
} ADCInputConfig;
typedef struct {
GPIO_TypeDef* const gpio; ///< One of GPIOX. For example, GPIOA.
const uint32_t gpio_pin; ///< One of GPIO_Pin_X.
bool active_high; ///< Pin is active high or active low
} OutputConfig;
//! Alternate function pin configuration
//! Used to configure a pin for use by a peripheral
typedef struct {
GPIO_TypeDef* const gpio; ///< One of GPIOX. For example, GPIOA.
const uint32_t gpio_pin; ///< One of GPIO_Pin_X.
const uint16_t gpio_pin_source; ///< One of GPIO_PinSourceX.
const uint8_t gpio_af; ///< One of GPIO_AF_X
} AfConfig;
typedef struct {
int i2c_address;
int axes_offsets[3];
bool axes_inverts[3];
} AccelConfig;
typedef struct {
int i2c_address;
int axes_offsets[3];
bool axes_inverts[3];
} MagConfig;
typedef struct {
I2C_TypeDef *const i2c;
AfConfig i2c_scl; ///< Alternate Function configuration for SCL pin
AfConfig i2c_sda; ///< Alternate Function configuration for SDA pin
uint32_t clock_ctrl; ///< Peripheral clock control flag
uint32_t clock_speed; ///< Bus clock speed
uint32_t duty_cycle; ///< Bus clock duty cycle in fast mode
const uint8_t ev_irq_channel; ///< I2C Event interrupt (One of X_IRQn). For example, I2C1_EV_IRQn.
const uint8_t er_irq_channel; ///< I2C Error interrupt (One of X_IRQn). For example, I2C1_ER_IRQn.
void (* const rail_cfg_fn)(void); //! Configure function for pins on this rail.
void (* const rail_ctl_fn)(bool enabled); //! Control function for this rail.
} I2cBusConfig;
typedef enum I2cDevice {
I2C_DEVICE_LIS3DH = 0,
I2C_DEVICE_MAG3110,
I2C_DEVICE_MFI,
I2C_DEVICE_LED_CONTROLLER,
I2C_DEVICE_MAX14690,
} I2cDevice;
typedef struct {
AfConfig i2s_ck;
AfConfig i2s_sd;
DMA_Stream_TypeDef *dma_stream;
uint32_t dma_channel;
uint32_t dma_channel_irq;
uint32_t dma_clock_ctrl;
SPI_TypeDef *spi;
uint32_t spi_clock_ctrl;
//! Pin we use to control power to the microphone. Only used on certain boards.
OutputConfig mic_gpio_power;
} MicConfig;
typedef enum {
OptionNotPresent = 0, // FIXME
OptionActiveLowOpenDrain,
OptionActiveHigh
} PowerCtl5VOptions;
typedef enum {
BacklightPinNoPwm = 0,
BacklightPinPwm,
BacklightIssiI2C
} BacklightOptions;
typedef enum {
VibePinNoPwm = 0,
VibePinPwm,
} VibeOptions;
typedef struct {
TIM_TypeDef* const peripheral; ///< A TIMx peripheral
const uint32_t config_clock; ///< One of RCC_APB1Periph_TIMx. For example, RCC_APB1Periph_TIM3.
void (* const init)(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct); ///< One of TIM_OCxInit
void (* const preload)(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload); ///< One of TIM_OCxPreloadConfig
} TimerConfig;
typedef enum {
CC2564A = 0,
CC2564B,
} BluetoothController;
typedef struct {
// I2C Configuration
/////////////////////////////////////////////////////////////////////////////
const I2cBusConfig *i2c_bus_configs;
const uint8_t i2c_bus_count;
const uint8_t *i2c_device_map;
const uint8_t i2c_device_count;
// Audio Configuration
/////////////////////////////////////////////////////////////////////////////
const bool has_mic;
const MicConfig mic_config;
// Ambient Light Configuration
/////////////////////////////////////////////////////////////////////////////
const bool has_ambient_light_sensor;
const uint32_t ambient_light_dark_threshold;
const OutputConfig photo_en;
const ADCInputConfig light_level;
// Debug Serial Configuration
/////////////////////////////////////////////////////////////////////////////
const ExtiConfig dbgserial_int;
// Accessory Configuration
/////////////////////////////////////////////////////////////////////////////
//! Enable power supply to the accessory connector.
const OutputConfig accessory_power_en;
const AfConfig accessory_rxtx_afcfg;
USART_TypeDef* const accessory_uart;
const ExtiConfig accessory_exti;
// Bluetooth Configuration
/////////////////////////////////////////////////////////////////////////////
const BluetoothController bt_controller;
const OutputConfig bt_shutdown;
const OutputConfig bt_cts_int;
const ExtiConfig bt_cts_exti;
const OutputConfig mfi_reset_pin;
// Display Configuration
/////////////////////////////////////////////////////////////////////////////
const OutputConfig lcd_com; //!< This needs to be pulsed regularly to keep the sharp display fresh.
const ExtiConfig cdone_int;
const ExtiConfig intn_int;
//! Controls power to the sharp display
const PowerCtl5VOptions power_5v0_options;
const OutputConfig power_ctl_5v0;
const BacklightOptions backlight_options;
const OutputConfig backlight_ctl;
const TimerConfig backlight_timer;
const AfConfig backlight_afcfg;
} BoardConfig;
// Button Configuration
/////////////////////////////////////////////////////////////////////////////
typedef struct {
const ButtonConfig buttons[NUM_BUTTONS];
const ButtonComConfig button_com;
} BoardConfigButton;
// Power Configuration
/////////////////////////////////////////////////////////////////////////////
typedef struct {
const ExtiConfig pmic_int;
//! Analog voltage of the battery read through an ADC.
const ADCInputConfig battery_vmon;
//! Tells us if the USB cable plugged in.
const InputConfig vusb_stat;
const ExtiConfig vusb_exti;
//! Tells us whether the charger thinks we're charging or not.
const InputConfig chg_stat;
//! Tell the charger to use 2x current to charge faster (MFG only).
const OutputConfig chg_fast;
//! Enable the charger. We may want to disable this in MFG, normally it's always on.
const OutputConfig chg_en;
//! Interrupt that fires when the USB cable is plugged in
const bool has_vusb_interrupt;
const bool wake_on_usb_power;
const int charging_status_led_voltage_compensation;
//! Percentage for watch only mode
const uint8_t low_power_threshold;
} BoardConfigPower;
typedef struct {
const AccelConfig accel_config;
const ExtiConfig accel_ints[2];
} BoardConfigAccel;
typedef struct {
const MagConfig mag_config;
const ExtiConfig mag_int;
} BoardConfigMag;
typedef struct {
const VibeOptions vibe_options;
const OutputConfig vibe_ctl;
const OutputConfig vibe_pwm;
const TimerConfig vibe_timer;
const AfConfig vibe_afcfg;
} BoardConfigVibe;
#include "board_definitions.h"

View file

@ -0,0 +1,29 @@
/*
* Copyright 2024 Google LLC
*
* Licensed 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, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#if BOARD_SNOWY_BB
#include "board_snowy_bb.h" // prototypes for Snowy bigboard
#elif BOARD_SNOWY_EVT
#include "board_snowy_evt.h" // prototypes for Snowy EVT
#elif BOARD_SNOWY_EVT2
#include "board_snowy_evt2.h" // prototypes for Snowy EVT2
#elif BOARD_SPALDING
#include "board_snowy_evt2.h" // Close enough
#else
#error "Unknown board definition"
#endif

View file

@ -0,0 +1,160 @@
/*
* Copyright 2024 Google LLC
*
* Licensed 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, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "util/misc.h"
#define USE_PARALLEL_FLASH
#define HAS_ACCESSORY_CONNECTOR
#define BOARD_HAS_PMIC
#define BOARD_I2C_BUS_COUNT (ARRAY_LENGTH(SNOWY_BB_I2C_BUS_CONFIGS))
extern void snowy_i2c_rail_1_ctl_fn(bool enable);
static const I2cBusConfig SNOWY_BB_I2C_BUS_CONFIGS[] = {
// labelled 1V8_I2C on the schematic
[0] = {
.i2c = I2C1,
.i2c_scl = { GPIOB, GPIO_Pin_6, GPIO_PinSource6, GPIO_AF_I2C1 },
.i2c_sda = { GPIOB, GPIO_Pin_9, GPIO_PinSource9, GPIO_AF_I2C1 },
.clock_speed = 400000,
.duty_cycle = I2C_DutyCycle_16_9,
.clock_ctrl = RCC_APB1Periph_I2C1,
.ev_irq_channel = I2C1_EV_IRQn,
.er_irq_channel = I2C1_ER_IRQn,
},
// labelled 2V5_I2C on the schematic
[1] = {
.i2c = I2C2,
.i2c_scl = { GPIOF, GPIO_Pin_1, GPIO_PinSource1, GPIO_AF_I2C2 },
.i2c_sda = { GPIOF, GPIO_Pin_0, GPIO_PinSource0, GPIO_AF_I2C2 },
.clock_speed = 400000,
.duty_cycle = I2C_DutyCycle_2,
.clock_ctrl = RCC_APB1Periph_I2C2,
.ev_irq_channel = I2C2_EV_IRQn,
.er_irq_channel = I2C2_ER_IRQn,
.rail_ctl_fn = snowy_i2c_rail_1_ctl_fn
}
};
static const uint8_t SNOWY_BB_I2C_DEVICE_MAP[] = {
[I2C_DEVICE_LIS3DH] = 0,
[I2C_DEVICE_MAG3110] = 1,
[I2C_DEVICE_MFI] = 1,
[I2C_DEVICE_MAX14690] = 0
};
static const BoardConfig BOARD_CONFIG = {
.i2c_bus_configs = SNOWY_BB_I2C_BUS_CONFIGS,
.i2c_bus_count = BOARD_I2C_BUS_COUNT,
.i2c_device_map = SNOWY_BB_I2C_DEVICE_MAP,
.i2c_device_count = ARRAY_LENGTH(SNOWY_BB_I2C_DEVICE_MAP),
.has_ambient_light_sensor = true,
.ambient_light_dark_threshold = 3000,
.photo_en = { GPIOA, GPIO_Pin_3, true },
.light_level = { GPIOA, GPIO_Pin_2, ADC_Channel_2 },
.dbgserial_int = { EXTI_PortSourceGPIOC, 12 },
.accessory_power_en = { GPIOF, GPIO_Pin_13, true },
.accessory_rxtx_afcfg = { GPIOE, GPIO_Pin_1, GPIO_PinSource1, GPIO_AF_UART8 },
.accessory_uart = UART8,
.accessory_exti = { EXTI_PortSourceGPIOE, 0 },
.bt_controller = CC2564A,
.bt_shutdown = { GPIOC, GPIO_Pin_8, false},
.bt_cts_int = { GPIOA, GPIO_Pin_11, false},
.bt_cts_exti = { EXTI_PortSourceGPIOA, 11 },
.mfi_reset_pin = { GPIOF, GPIO_Pin_11 },
// Only used with Sharp displays
.lcd_com = { 0 },
.cdone_int = { EXTI_PortSourceGPIOG, 9 },
.intn_int = { EXTI_PortSourceGPIOG, 10 },
.power_5v0_options = OptionNotPresent,
.power_ctl_5v0 = { 0 },
.backlight_options = BacklightPinPwm,
.backlight_ctl = { GPIOB, GPIO_Pin_14, true },
.backlight_timer = {
.peripheral = TIM12,
.config_clock = RCC_APB1Periph_TIM12,
.init = TIM_OC1Init,
.preload = TIM_OC1PreloadConfig
},
.backlight_afcfg = { GPIOB, GPIO_Pin_14, GPIO_PinSource14, GPIO_AF_TIM12 },
.has_mic = true,
.mic_config = {
.i2s_ck = { GPIOB, GPIO_Pin_10, GPIO_PinSource10, GPIO_AF_SPI2 },
.i2s_sd = { GPIOB, GPIO_Pin_15, GPIO_PinSource15, GPIO_AF_SPI2 },
.dma_stream = DMA1_Stream3,
.dma_channel = DMA_Channel_0,
.dma_channel_irq = DMA1_Stream3_IRQn,
.dma_clock_ctrl = RCC_AHB1Periph_DMA1,
.spi = SPI2,
.spi_clock_ctrl = RCC_APB1Periph_SPI2
},
};
static const BoardConfigButton BOARD_CONFIG_BUTTON = {
.buttons = {
[BUTTON_ID_BACK] = { "Back", GPIOG, GPIO_Pin_4, { EXTI_PortSourceGPIOG, 4 }, GPIO_PuPd_NOPULL },
[BUTTON_ID_UP] = { "Up", GPIOG, GPIO_Pin_3, { EXTI_PortSourceGPIOG, 3 }, GPIO_PuPd_NOPULL },
[BUTTON_ID_SELECT] = { "Select", GPIOG, GPIO_Pin_1, { EXTI_PortSourceGPIOG, 1 }, GPIO_PuPd_NOPULL },
[BUTTON_ID_DOWN] = { "Down", GPIOG, GPIO_Pin_2, { EXTI_PortSourceGPIOG, 2 }, GPIO_PuPd_NOPULL },
},
.button_com = { 0 },
};
static const BoardConfigPower BOARD_CONFIG_POWER = {
.pmic_int = { EXTI_PortSourceGPIOG, 7 },
.battery_vmon = { GPIOA, GPIO_Pin_1, ADC_Channel_1 },
.vusb_stat = { .gpio = GPIO_Port_NULL, },
.chg_stat = { GPIO_Port_NULL },
.chg_fast = { GPIO_Port_NULL },
.chg_en = { GPIO_Port_NULL },
.has_vusb_interrupt = false,
.wake_on_usb_power = false,
.charging_status_led_voltage_compensation = 0,
.low_power_threshold = 5,
};
static const BoardConfigVibe BOARD_CONFIG_VIBE = {
.vibe_options = VibePinPwm,
.vibe_ctl = { GPIOF, GPIO_Pin_4, true },
.vibe_pwm = { GPIOB, GPIO_Pin_8, true },
.vibe_timer = {
.peripheral = TIM10,
.config_clock = RCC_APB2Periph_TIM10,
.init = TIM_OC1Init,
.preload = TIM_OC1PreloadConfig
},
.vibe_afcfg = { GPIOB, GPIO_Pin_8, GPIO_PinSource8, GPIO_AF_TIM10 },
};

View file

@ -0,0 +1,202 @@
/*
* Copyright 2024 Google LLC
*
* Licensed 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, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "util/misc.h"
#include "drivers/accel.h"
#include "drivers/imu/bmi160/bmi160.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_exti.h"
#include "stm32f4xx_syscfg.h"
#include "stm32f4xx_i2c.h"
#define USE_PARALLEL_FLASH
#define HAS_ACCESSORY_CONNECTOR
#define BOARD_HAS_PMIC
#define BOARD_I2C_BUS_COUNT (ARRAY_LENGTH(SNOWY_EVT_I2C_BUS_CONFIGS))
extern void snowy_i2c_rail_1_ctl_fn(bool enable);
static const I2cBusConfig SNOWY_EVT_I2C_BUS_CONFIGS[] = {
// Listed as I2C_PMIC on the schematic, runs at 1.8V
[0] = {
.i2c = I2C1,
.i2c_scl = { GPIOB, GPIO_Pin_6, GPIO_PinSource6, GPIO_AF_I2C1 },
.i2c_sda = { GPIOB, GPIO_Pin_9, GPIO_PinSource9, GPIO_AF_I2C1 },
.clock_speed = 400000,
.duty_cycle = I2C_DutyCycle_16_9,
.clock_ctrl = RCC_APB1Periph_I2C1,
.ev_irq_channel = I2C1_EV_IRQn,
.er_irq_channel = I2C1_ER_IRQn,
},
// Listed as I2C_MFI on the schematic, runs at 1.8V
[1] = {
.i2c = I2C2,
.i2c_scl = { GPIOF, GPIO_Pin_1, GPIO_PinSource1, GPIO_AF_I2C2 },
.i2c_sda = { GPIOF, GPIO_Pin_0, GPIO_PinSource0, GPIO_AF_I2C2 },
.clock_speed = 400000,
.duty_cycle = I2C_DutyCycle_2,
.clock_ctrl = RCC_APB1Periph_I2C2,
.ev_irq_channel = I2C2_EV_IRQn,
.er_irq_channel = I2C2_ER_IRQn,
.rail_ctl_fn = snowy_i2c_rail_1_ctl_fn
}
};
static const uint8_t SNOWY_EVT_I2C_DEVICE_MAP[] = {
[I2C_DEVICE_MFI] = 1,
[I2C_DEVICE_MAX14690] = 0
};
static const BoardConfig BOARD_CONFIG = {
.i2c_bus_configs = SNOWY_EVT_I2C_BUS_CONFIGS,
.i2c_bus_count = BOARD_I2C_BUS_COUNT,
.i2c_device_map = SNOWY_EVT_I2C_DEVICE_MAP,
.i2c_device_count = ARRAY_LENGTH(SNOWY_EVT_I2C_DEVICE_MAP),
.has_ambient_light_sensor = true,
.ambient_light_dark_threshold = 3000,
.photo_en = { GPIOA, GPIO_Pin_3, true },
.light_level = { GPIOA, GPIO_Pin_2, ADC_Channel_2 },
.dbgserial_int = { EXTI_PortSourceGPIOC, 12 },
.accessory_power_en = { GPIOF, GPIO_Pin_13, true },
.accessory_rxtx_afcfg = { GPIOE, GPIO_Pin_1, GPIO_PinSource1, GPIO_AF_UART8 },
.accessory_uart = UART8,
.accessory_exti = { EXTI_PortSourceGPIOE, 0 },
.bt_controller = CC2564B,
.bt_shutdown = { GPIOC, GPIO_Pin_8, false},
.bt_cts_int = { GPIOA, GPIO_Pin_11, false},
.bt_cts_exti = { EXTI_PortSourceGPIOA, 11 },
.mfi_reset_pin = { GPIOF, GPIO_Pin_11 },
// Only used with Sharp displays
.lcd_com = { 0 },
.cdone_int = { EXTI_PortSourceGPIOG, 9 },
.intn_int = { EXTI_PortSourceGPIOG, 10 },
.power_5v0_options = OptionNotPresent,
.power_ctl_5v0 = { 0 },
.backlight_options = BacklightPinPwm,
.backlight_ctl = { GPIOB, GPIO_Pin_14, true },
.backlight_timer = {
.peripheral = TIM12,
.config_clock = RCC_APB1Periph_TIM12,
.init = TIM_OC1Init,
.preload = TIM_OC1PreloadConfig
},
.backlight_afcfg = { GPIOB, GPIO_Pin_14, GPIO_PinSource14, GPIO_AF_TIM12 },
.has_mic = true,
.mic_config = {
.i2s_ck = { GPIOB, GPIO_Pin_10, GPIO_PinSource10, GPIO_AF_SPI2 },
.i2s_sd = { GPIOB, GPIO_Pin_15, GPIO_PinSource15, GPIO_AF_SPI2 },
.dma_stream = DMA1_Stream3,
.dma_channel = DMA_Channel_0,
.dma_channel_irq = DMA1_Stream3_IRQn,
.dma_clock_ctrl = RCC_AHB1Periph_DMA1,
.spi = SPI2,
.spi_clock_ctrl = RCC_APB1Periph_SPI2,
.mic_gpio_power = { GPIOF, GPIO_Pin_5, true }
},
};
static const BoardConfigButton BOARD_CONFIG_BUTTON = {
.buttons = {
[BUTTON_ID_BACK] = { "Back", GPIOG, GPIO_Pin_1, { EXTI_PortSourceGPIOG, 1 }, GPIO_PuPd_UP },
[BUTTON_ID_UP] = { "Up", GPIOG, GPIO_Pin_2, { EXTI_PortSourceGPIOG, 2 }, GPIO_PuPd_UP },
[BUTTON_ID_SELECT] = { "Select", GPIOG, GPIO_Pin_3, { EXTI_PortSourceGPIOG, 3 }, GPIO_PuPd_UP },
[BUTTON_ID_DOWN] = { "Down", GPIOG, GPIO_Pin_4, { EXTI_PortSourceGPIOG, 4 }, GPIO_PuPd_NOPULL },
},
.button_com = { 0 },
};
static const BoardConfigPower BOARD_CONFIG_POWER = {
.pmic_int = { EXTI_PortSourceGPIOG, 7 },
.battery_vmon = { GPIOA, GPIO_Pin_1, ADC_Channel_1 },
.vusb_stat = { .gpio = GPIO_Port_NULL, },
.chg_stat = { GPIO_Port_NULL },
.chg_fast = { GPIO_Port_NULL },
.chg_en = { GPIO_Port_NULL },
.has_vusb_interrupt = false,
.wake_on_usb_power = false,
.charging_status_led_voltage_compensation = 0,
.low_power_threshold = 5,
};
static const BoardConfigAccel BOARD_CONFIG_ACCEL = {
// FIXME: We no longer use i2c for our accel, this will need work.
.accel_config = {
.i2c_address = 0x32,
.axes_offsets[ACCEL_AXIS_X] = 1,
.axes_offsets[ACCEL_AXIS_Y] = 0,
.axes_offsets[ACCEL_AXIS_Z] = 2,
.axes_inverts[ACCEL_AXIS_X] = true,
.axes_inverts[ACCEL_AXIS_Y] = false,
.axes_inverts[ACCEL_AXIS_Z] = true,
},
.accel_ints = {
[0] = { EXTI_PortSourceGPIOG, 5 },
[1] = { EXTI_PortSourceGPIOG, 6 }
},
};
static const BoardConfigMag BOARD_CONFIG_MAG = {
// FIXME: We need to talk to the compass through the accel now as it's hanging of the accel's i2c bus.
// This will need work.
.mag_config = {
.i2c_address = 0x0e << 1,
// FIXME: ?
.axes_offsets[ACCEL_AXIS_X] = 1,
.axes_offsets[ACCEL_AXIS_Y] = 0,
.axes_offsets[ACCEL_AXIS_Z] = 2,
.axes_inverts[ACCEL_AXIS_X] = false,
.axes_inverts[ACCEL_AXIS_Y] = true,
.axes_inverts[ACCEL_AXIS_Z] = true,
},
.mag_int = { EXTI_PortSourceGPIOF, 14 },
};
static const BoardConfigVibe BOARD_CONFIG_VIBE = {
.vibe_options = VibePinPwm,
.vibe_ctl = { GPIOF, GPIO_Pin_4, true },
.vibe_pwm = { GPIOB, GPIO_Pin_8, true },
.vibe_timer = {
.peripheral = TIM10,
.config_clock = RCC_APB2Periph_TIM10,
.init = TIM_OC1Init,
.preload = TIM_OC1PreloadConfig
},
.vibe_afcfg = { GPIOB, GPIO_Pin_8, GPIO_PinSource8, GPIO_AF_TIM10 },
};

View file

@ -0,0 +1,158 @@
/*
* Copyright 2024 Google LLC
*
* Licensed 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, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "util/misc.h"
#define USE_PARALLEL_FLASH
#define HAS_ACCESSORY_CONNECTOR
#define BOARD_HAS_PMIC
#define BOARD_I2C_BUS_COUNT (ARRAY_LENGTH(SNOWY_EVT2_I2C_BUS_CONFIGS))
extern void snowy_i2c_rail_1_ctl_fn(bool enable);
static const I2cBusConfig SNOWY_EVT2_I2C_BUS_CONFIGS[] = {
// Listed as I2C_PMIC_MAG on the schematic, runs at 1.8V
[0] = {
.i2c = I2C1,
.i2c_scl = { GPIOB, GPIO_Pin_6, GPIO_PinSource6, GPIO_AF_I2C1 },
.i2c_sda = { GPIOB, GPIO_Pin_9, GPIO_PinSource9, GPIO_AF_I2C1 },
.clock_speed = 400000,
.duty_cycle = I2C_DutyCycle_16_9,
.clock_ctrl = RCC_APB1Periph_I2C1,
.ev_irq_channel = I2C1_EV_IRQn,
.er_irq_channel = I2C1_ER_IRQn,
},
// Listed as I2C_MFI on the schematic, runs at 1.8V
[1] = {
.i2c = I2C2,
.i2c_scl = { GPIOF, GPIO_Pin_1, GPIO_PinSource1, GPIO_AF_I2C2 },
.i2c_sda = { GPIOF, GPIO_Pin_0, GPIO_PinSource0, GPIO_AF_I2C2 },
.clock_speed = 400000,
.duty_cycle = I2C_DutyCycle_2,
.clock_ctrl = RCC_APB1Periph_I2C2,
.ev_irq_channel = I2C2_EV_IRQn,
.er_irq_channel = I2C2_ER_IRQn,
.rail_ctl_fn = snowy_i2c_rail_1_ctl_fn
}
};
static const uint8_t SNOWY_EVT2_I2C_DEVICE_MAP[] = {
[I2C_DEVICE_MAG3110] = 0,
[I2C_DEVICE_MFI] = 1,
[I2C_DEVICE_MAX14690] = 0
};
static const BoardConfig BOARD_CONFIG = {
.i2c_bus_configs = SNOWY_EVT2_I2C_BUS_CONFIGS,
.i2c_bus_count = BOARD_I2C_BUS_COUNT,
.i2c_device_map = SNOWY_EVT2_I2C_DEVICE_MAP,
.i2c_device_count = ARRAY_LENGTH(SNOWY_EVT2_I2C_DEVICE_MAP),
.has_ambient_light_sensor = true,
.ambient_light_dark_threshold = 3000,
.photo_en = { GPIOA, GPIO_Pin_3, true },
.light_level = { GPIOA, GPIO_Pin_2, ADC_Channel_2 },
.dbgserial_int = { EXTI_PortSourceGPIOC, 12 },
.accessory_power_en = { GPIOF, GPIO_Pin_13, true },
.accessory_rxtx_afcfg = { GPIOE, GPIO_Pin_1, GPIO_PinSource1, GPIO_AF_UART8 },
.accessory_uart = UART8,
.accessory_exti = { EXTI_PortSourceGPIOE, 0 },
.bt_controller = CC2564B,
.bt_shutdown = { GPIOB, GPIO_Pin_12, false},
.bt_cts_int = { GPIOA, GPIO_Pin_11, false},
.bt_cts_exti = { EXTI_PortSourceGPIOA, 11 },
// Only used with Sharp displays
.lcd_com = { 0 },
.cdone_int = { EXTI_PortSourceGPIOG, 9 },
.intn_int = { EXTI_PortSourceGPIOG, 10 },
.power_5v0_options = OptionNotPresent,
.power_ctl_5v0 = { 0 },
.backlight_options = BacklightPinPwm,
.backlight_ctl = { GPIOB, GPIO_Pin_14, true },
.backlight_timer = {
.peripheral = TIM12,
.config_clock = RCC_APB1Periph_TIM12,
.init = TIM_OC1Init,
.preload = TIM_OC1PreloadConfig
},
.backlight_afcfg = { GPIOB, GPIO_Pin_14, GPIO_PinSource14, GPIO_AF_TIM12 },
.has_mic = true,
.mic_config = {
.i2s_ck = { GPIOB, GPIO_Pin_10, GPIO_PinSource10, GPIO_AF_SPI2 },
.i2s_sd = { GPIOB, GPIO_Pin_15, GPIO_PinSource15, GPIO_AF_SPI2 },
.dma_stream = DMA1_Stream3,
.dma_channel = DMA_Channel_0,
.dma_channel_irq = DMA1_Stream3_IRQn,
.dma_clock_ctrl = RCC_AHB1Periph_DMA1,
.spi = SPI2,
.spi_clock_ctrl = RCC_APB1Periph_SPI2,
.mic_gpio_power = { GPIOF, GPIO_Pin_5, true }
},
};
static const BoardConfigButton BOARD_CONFIG_BUTTON = {
.buttons = {
[BUTTON_ID_BACK] = { "Back", GPIOG, GPIO_Pin_4, { EXTI_PortSourceGPIOG, 4 }, GPIO_PuPd_NOPULL },
[BUTTON_ID_UP] = { "Up", GPIOG, GPIO_Pin_3, { EXTI_PortSourceGPIOG, 3 }, GPIO_PuPd_UP },
[BUTTON_ID_SELECT] = { "Select", GPIOG, GPIO_Pin_1, { EXTI_PortSourceGPIOG, 1 }, GPIO_PuPd_UP },
[BUTTON_ID_DOWN] = { "Down", GPIOG, GPIO_Pin_2, { EXTI_PortSourceGPIOG, 2 }, GPIO_PuPd_UP },
},
.button_com = { 0 },
};
static const BoardConfigPower BOARD_CONFIG_POWER = {
.pmic_int = { EXTI_PortSourceGPIOG, 7 },
.battery_vmon = { GPIOA, GPIO_Pin_1, ADC_Channel_1 },
.vusb_stat = { .gpio = GPIO_Port_NULL, },
.chg_stat = { GPIO_Port_NULL },
.chg_fast = { GPIO_Port_NULL },
.chg_en = { GPIO_Port_NULL },
.has_vusb_interrupt = false,
.wake_on_usb_power = false,
.charging_status_led_voltage_compensation = 0,
.low_power_threshold = 5,
};
static const BoardConfigVibe BOARD_CONFIG_VIBE = {
.vibe_options = VibePinPwm,
.vibe_ctl = { GPIOF, GPIO_Pin_4, true },
.vibe_pwm = { GPIOB, GPIO_Pin_8, true },
.vibe_timer = {
.peripheral = TIM10,
.config_clock = RCC_APB2Periph_TIM10,
.init = TIM_OC1Init,
.preload = TIM_OC1PreloadConfig
},
.vibe_afcfg = { GPIOB, GPIO_Pin_8, GPIO_PinSource8, GPIO_AF_TIM10 },
};