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,105 @@
/*
* 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 "display.h"
#include "drivers/button_id.h"
#include "stm32f7xx.h"
#include <stdint.h>
#include <stdbool.h>
#define GPIO_Port_NULL ((GPIO_TypeDef *) 0)
#define GPIO_Pin_NULL ((uint16_t)0x0000)
// This is generated in order to faciliate the check within the IRQ_MAP macro below
enum {
#define IRQ_DEF(num, irq) IS_VALID_IRQ__##irq,
#include "irq_stm32f7.def"
#undef IRQ_DEF
};
//! Creates a trampoline to the interrupt handler defined within the driver
#define IRQ_MAP(irq, handler, device) \
void irq##_IRQHandler(void) { \
handler(device); \
} \
_Static_assert(IS_VALID_IRQ__##irq || true, "(See comment below)")
/*
* The above static assert checks that the requested IRQ is valid by checking that the enum
* value (generated above) is declared. The static assert itself will not trip, but you will get
* a compilation error from that line if the IRQ does not exist within irq_stm32*.def.
*/
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 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 {
InputConfig input;
GPIOPuPd_TypeDef pupd;
} ButtonConfig;
// Button Configuration
/////////////////////////////////////////////////////////////////////////////
typedef struct {
const ButtonConfig buttons[NUM_BUTTONS];
} BoardConfigButton;
// Power Configuration
/////////////////////////////////////////////////////////////////////////////
typedef struct {
//! Voltage rail control lines
const OutputConfig rail_4V5_ctrl;
const OutputConfig rail_6V6_ctrl;
} BoardConfigPower;
typedef struct {
OutputConfig reset_gpio;
} BoardConfigFlash;
typedef struct {
const OutputConfig power_en; //< Enable power supply to the accessory connector.
} BoardConfigAccessory;
typedef const struct SPIBus SPIBus;
typedef const struct SPISlavePort SPISlavePort;
typedef const struct I2CBus I2CBus;
typedef const struct I2CSlavePort I2CSlavePort;
typedef const struct ICE40LPDevice ICE40LPDevice;
void board_init(void);
#include "board_definitions.h"

View file

@ -0,0 +1,25 @@
/*
* 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_ROBERT_BB || BOARD_ROBERT_BB2
#include "board_robert_bb.h"
#elif BOARD_ROBERT_EVT
#include "board_robert_evt.h"
#else
#error "Unknown board definition"
#endif

View file

@ -0,0 +1,114 @@
/*
* 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.
*/
#include "board/board.h"
#include "drivers/i2c/i2c_definitions.h"
#include "drivers/i2c/i2c_hal_definitions.h"
#include "drivers/display/ice40lp_definitions.h"
#include "util/misc.h"
//
// iCE40LP configuration
//
static ICE40LPDevice ICE40LP_DEVICE = {
.spi = {
.periph = SPI6,
.rcc_bit = RCC_APB2Periph_SPI6,
.clk = {
.gpio = GPIOA,
.gpio_pin = GPIO_Pin_5,
.gpio_pin_source = GPIO_PinSource5,
.gpio_af = GPIO_AF8_SPI6
},
.mosi = {
.gpio = GPIOA,
.gpio_pin = GPIO_Pin_7,
.gpio_pin_source = GPIO_PinSource7,
.gpio_af = GPIO_AF8_SPI6
},
.scs = {
.gpio = GPIOA,
.gpio_pin = GPIO_Pin_4,
.active_high = false
}
},
.creset = {
.gpio = GPIOA,
.gpio_pin = GPIO_Pin_3,
.active_high = true,
},
.cdone = {
.gpio = GPIOB,
.gpio_pin = GPIO_Pin_2,
},
.busy = {
.gpio = GPIOB,
.gpio_pin = GPIO_Pin_0,
},
.use_6v6_rail = true,
};
ICE40LPDevice * const ICE40LP = &ICE40LP_DEVICE;
// I2C DEVICES
static I2CBusState I2C_PMIC_MAG_BUS_STATE = {};
static const I2CBusHal I2C_PMIC_MAG_BUS_HAL = {
.i2c = I2C4,
.clock_ctrl = RCC_APB1Periph_I2C4,
.clock_speed = 400000,
.duty_cycle = I2CDutyCycle_16_9,
.ev_irq_channel = I2C4_EV_IRQn,
.er_irq_channel = I2C4_ER_IRQn,
};
static const I2CBus I2C_PMIC_MAG_BUS = {
.state = &I2C_PMIC_MAG_BUS_STATE,
.hal = &I2C_PMIC_MAG_BUS_HAL,
.scl_gpio = {
.gpio = GPIOF,
.gpio_pin = GPIO_Pin_14,
.gpio_pin_source = GPIO_PinSource14,
.gpio_af = GPIO_AF4_I2C4
},
.sda_gpio = {
.gpio = GPIOF,
.gpio_pin = GPIO_Pin_15,
.gpio_pin_source = GPIO_PinSource15,
.gpio_af = GPIO_AF4_I2C4
},
.name = "I2C_PMIC_MAG"
};
static const I2CSlavePort I2C_SLAVE_MAX14690 = {
.bus = &I2C_PMIC_MAG_BUS,
.address = 0x50
};
I2CSlavePort * const I2C_MAX14690 = &I2C_SLAVE_MAX14690;
IRQ_MAP(I2C4_EV, i2c_hal_event_irq_handler, &I2C_PMIC_MAG_BUS);
IRQ_MAP(I2C4_ER, i2c_hal_error_irq_handler, &I2C_PMIC_MAG_BUS);
void board_init(void) {
i2c_init(&I2C_PMIC_MAG_BUS);
}

View file

@ -0,0 +1,132 @@
/*
* 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
// ----------------------------------------------
// Board definitions for Robert BB (C2 Bigboard)
// ----------------------------------------------
//
#include "util/size.h"
#define BOARD_LSE_MODE RCC_LSE_Bypass
static const BoardConfigButton BOARD_CONFIG_BUTTON = {
.buttons = {
[BUTTON_ID_BACK] = {
.input = {
.gpio = GPIOG,
.gpio_pin = GPIO_Pin_6,
},
.pupd = GPIO_PuPd_UP
},
[BUTTON_ID_UP] = {
.input = {
.gpio = GPIOG,
.gpio_pin = GPIO_Pin_3,
},
.pupd = GPIO_PuPd_NOPULL
},
[BUTTON_ID_SELECT] = {
.input = {
.gpio = GPIOG,
.gpio_pin = GPIO_Pin_5,
},
.pupd = GPIO_PuPd_UP
},
[BUTTON_ID_DOWN] = {
.input = {
.gpio = GPIOG,
.gpio_pin = GPIO_Pin_4,
},
.pupd = GPIO_PuPd_UP
},
},
};
static const BoardConfigPower BOARD_CONFIG_POWER = {
.rail_4V5_ctrl = {
.gpio = GPIOH,
.gpio_pin = GPIO_Pin_5,
.active_high = true,
},
.rail_6V6_ctrl = {
.gpio = GPIOH,
.gpio_pin = GPIO_Pin_3,
.active_high = true,
},
};
static const BoardConfigFlash BOARD_CONFIG_FLASH = {
};
static const BoardConfigAccessory BOARD_CONFIG_ACCESSORY = {
.power_en = { GPIOA, GPIO_Pin_11, true },
};
typedef enum {
QSpiPin_CS,
QSpiPin_SCLK,
QSpiPin_DQ0,
QSpiPin_DQ1,
QSpiPin_DQ2,
QSpiPin_DQ3,
QSpiPinCount,
} QSpiPin;
static const AfConfig BOARD_CONFIG_FLASH_PINS[] = {
[QSpiPin_CS] = {
.gpio = GPIOB,
.gpio_pin = GPIO_Pin_10,
.gpio_pin_source = GPIO_PinSource10,
.gpio_af = GPIO_AF9_QUADSPI,
},
[QSpiPin_SCLK] = {
.gpio = GPIOF,
.gpio_pin = GPIO_Pin_10,
.gpio_pin_source = GPIO_PinSource10,
.gpio_af = GPIO_AF9_QUADSPI,
},
[QSpiPin_DQ0] = {
.gpio = GPIOD,
.gpio_pin = GPIO_Pin_11,
.gpio_pin_source = GPIO_PinSource11,
.gpio_af = GPIO_AF9_QUADSPI,
},
[QSpiPin_DQ1] = {
.gpio = GPIOC,
.gpio_pin = GPIO_Pin_10,
.gpio_pin_source = GPIO_PinSource10,
.gpio_af = GPIO_AF9_QUADSPI,
},
[QSpiPin_DQ2] = {
.gpio = GPIOF,
.gpio_pin = GPIO_Pin_7,
.gpio_pin_source = GPIO_PinSource7,
.gpio_af = GPIO_AF9_QUADSPI,
},
[QSpiPin_DQ3] = {
.gpio = GPIOA,
.gpio_pin = GPIO_Pin_1,
.gpio_pin_source = GPIO_PinSource1,
.gpio_af = GPIO_AF9_QUADSPI,
},
};
extern I2CSlavePort * const I2C_MAX14690;
extern ICE40LPDevice * const ICE40LP;

View file

@ -0,0 +1,114 @@
/*
* 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.
*/
#include "board/board.h"
#include "drivers/i2c/i2c_definitions.h"
#include "drivers/i2c/i2c_hal_definitions.h"
#include "drivers/display/ice40lp_definitions.h"
#include "util/misc.h"
//
// iCE40LP configuration
//
static ICE40LPDevice ICE40LP_DEVICE = {
.spi = {
.periph = SPI6,
.rcc_bit = RCC_APB2Periph_SPI6,
.clk = {
.gpio = GPIOA,
.gpio_pin = GPIO_Pin_5,
.gpio_pin_source = GPIO_PinSource5,
.gpio_af = GPIO_AF8_SPI6
},
.mosi = {
.gpio = GPIOA,
.gpio_pin = GPIO_Pin_7,
.gpio_pin_source = GPIO_PinSource7,
.gpio_af = GPIO_AF8_SPI6
},
.scs = {
.gpio = GPIOA,
.gpio_pin = GPIO_Pin_4,
.active_high = false
}
},
.creset = {
.gpio = GPIOA,
.gpio_pin = GPIO_Pin_3,
.active_high = true,
},
.cdone = {
.gpio = GPIOB,
.gpio_pin = GPIO_Pin_2,
},
.busy = {
.gpio = GPIOB,
.gpio_pin = GPIO_Pin_0,
},
.use_6v6_rail = false,
};
ICE40LPDevice * const ICE40LP = &ICE40LP_DEVICE;
// I2C DEVICES
static I2CBusState I2C_PMIC_MAG_BUS_STATE = {};
static const I2CBusHal I2C_PMIC_MAG_BUS_HAL = {
.i2c = I2C4,
.clock_ctrl = RCC_APB1Periph_I2C4,
.clock_speed = 400000,
.duty_cycle = I2CDutyCycle_16_9,
.ev_irq_channel = I2C4_EV_IRQn,
.er_irq_channel = I2C4_ER_IRQn,
};
static const I2CBus I2C_PMIC_MAG_BUS = {
.state = &I2C_PMIC_MAG_BUS_STATE,
.hal = &I2C_PMIC_MAG_BUS_HAL,
.scl_gpio = {
.gpio = GPIOF,
.gpio_pin = GPIO_Pin_14,
.gpio_pin_source = GPIO_PinSource14,
.gpio_af = GPIO_AF4_I2C4
},
.sda_gpio = {
.gpio = GPIOF,
.gpio_pin = GPIO_Pin_15,
.gpio_pin_source = GPIO_PinSource15,
.gpio_af = GPIO_AF4_I2C4
},
.name = "I2C_PMIC_MAG"
};
static const I2CSlavePort I2C_SLAVE_MAX14690 = {
.bus = &I2C_PMIC_MAG_BUS,
.address = 0x50
};
I2CSlavePort * const I2C_MAX14690 = &I2C_SLAVE_MAX14690;
IRQ_MAP(I2C4_EV, i2c_hal_event_irq_handler, &I2C_PMIC_MAG_BUS);
IRQ_MAP(I2C4_ER, i2c_hal_error_irq_handler, &I2C_PMIC_MAG_BUS);
void board_init(void) {
i2c_init(&I2C_PMIC_MAG_BUS);
}

View file

@ -0,0 +1,133 @@
/*
* 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
// ----------------------------------------------
// Board definitions for Robert EVT
// ----------------------------------------------
//
#include "util/size.h"
#define BOARD_LSE_MODE RCC_LSE_Bypass
static const BoardConfigButton BOARD_CONFIG_BUTTON = {
.buttons = {
[BUTTON_ID_BACK] = {
.input = {
.gpio = GPIOG,
.gpio_pin = GPIO_Pin_3,
},
.pupd = GPIO_PuPd_NOPULL,
},
[BUTTON_ID_UP] = {
.input = {
.gpio = GPIOG,
.gpio_pin = GPIO_Pin_4,
},
.pupd = GPIO_PuPd_UP,
},
[BUTTON_ID_SELECT] = {
.input = {
.gpio = GPIOG,
.gpio_pin = GPIO_Pin_5,
},
.pupd = GPIO_PuPd_UP,
},
[BUTTON_ID_DOWN] = {
.input = {
.gpio = GPIOG,
.gpio_pin = GPIO_Pin_6,
},
.pupd = GPIO_PuPd_UP,
},
},
};
static const BoardConfigPower BOARD_CONFIG_POWER = {
.rail_4V5_ctrl = {
.gpio = GPIOH,
.gpio_pin = GPIO_Pin_5,
.active_high = true,
},
.rail_6V6_ctrl = { GPIO_Port_NULL },
};
static const BoardConfigFlash BOARD_CONFIG_FLASH = {
.reset_gpio = {
.gpio = GPIOE,
.gpio_pin = GPIO_Pin_15,
.active_high = false,
},
};
static const BoardConfigAccessory BOARD_CONFIG_ACCESSORY = {
.power_en = { GPIOD, GPIO_Pin_2, true },
};
typedef enum {
QSpiPin_CS,
QSpiPin_SCLK,
QSpiPin_DQ0,
QSpiPin_DQ1,
QSpiPin_DQ2,
QSpiPin_DQ3,
QSpiPinCount,
} QSpiPin;
static const AfConfig BOARD_CONFIG_FLASH_PINS[] = {
[QSpiPin_CS] = {
.gpio = GPIOB,
.gpio_pin = GPIO_Pin_10,
.gpio_pin_source = GPIO_PinSource10,
.gpio_af = GPIO_AF9_QUADSPI,
},
[QSpiPin_SCLK] = {
.gpio = GPIOF,
.gpio_pin = GPIO_Pin_10,
.gpio_pin_source = GPIO_PinSource10,
.gpio_af = GPIO_AF9_QUADSPI,
},
[QSpiPin_DQ0] = {
.gpio = GPIOD,
.gpio_pin = GPIO_Pin_11,
.gpio_pin_source = GPIO_PinSource11,
.gpio_af = GPIO_AF9_QUADSPI,
},
[QSpiPin_DQ1] = {
.gpio = GPIOC,
.gpio_pin = GPIO_Pin_10,
.gpio_pin_source = GPIO_PinSource10,
.gpio_af = GPIO_AF9_QUADSPI,
},
[QSpiPin_DQ2] = {
.gpio = GPIOE,
.gpio_pin = GPIO_Pin_2,
.gpio_pin_source = GPIO_PinSource2,
.gpio_af = GPIO_AF9_QUADSPI,
},
[QSpiPin_DQ3] = {
.gpio = GPIOA,
.gpio_pin = GPIO_Pin_1,
.gpio_pin_source = GPIO_PinSource1,
.gpio_af = GPIO_AF9_QUADSPI,
},
};
extern I2CSlavePort * const I2C_MAX14690;
extern ICE40LPDevice * const ICE40LP;

View file

@ -0,0 +1,33 @@
/*
* 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
#define DISP_COLS 200
#define DISP_ROWS 228
#define DISPLAY_FRAMEBUFFER_BYTES (DISP_COLS * DISP_ROWS)
#define DISPLAY_ORIENTATION_COLUMN_MAJOR_INVERTED 0
#define DISPLAY_ORIENTATION_ROTATED_180 0
#define DISPLAY_ORIENTATION_ROW_MAJOR 0
#define DISPLAY_ORIENTATION_ROW_MAJOR_INVERTED 1
#define PBL_BW 0
#define PBL_RECT 1
#define PBL_ROUND 0
#define PBL_COLOR 1