42 #include "board_hw_defs.c"
47 #include <uavobjectsinit.h>
49 #include "hwseppuku.h"
50 #include "manualcontrolsettings.h"
51 #include "modulesettings.h"
52 #include "onscreendisplaysettings.h"
54 #if defined(PIOS_INCLUDE_WS2811)
55 #include "rgbledsettings.h"
68 #if defined(PIOS_INCLUDE_VIDEO)
69 void OSD_configure_bw_levels(
void)
71 GPIO_InitTypeDef GPIO_InitStructure;
72 TIM_OCInitTypeDef TIM_OCInitStructure;
73 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
76 GPIO_StructInit(&GPIO_InitStructure);
77 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_15;
78 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
79 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
80 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
81 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
82 GPIO_Init(GPIOB, &GPIO_InitStructure);
84 GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_TIM11);
85 GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_TIM12);
88 TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
89 TIM_TimeBaseStructure.TIM_Prescaler = 0;
90 TIM_TimeBaseStructure.TIM_Period = 192;
91 TIM_TimeBaseStructure.TIM_ClockDivision = 0;
92 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
93 TIM_TimeBaseInit(TIM11, &TIM_TimeBaseStructure);
94 TIM_TimeBaseInit(TIM12, &TIM_TimeBaseStructure);
97 TIM_OCStructInit(&TIM_OCInitStructure);
98 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
99 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
100 TIM_OCInitStructure.TIM_Pulse = 90;
101 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
103 TIM_OC1Init(TIM11, &TIM_OCInitStructure);
104 TIM_OC2Init(TIM12, &TIM_OCInitStructure);
107 TIM_CtrlPWMOutputs(TIM11, ENABLE);
108 TIM_CtrlPWMOutputs(TIM12, ENABLE);
111 TIM_Cmd(TIM11, ENABLE);
112 TIM_Cmd(TIM12, ENABLE);
130 #if defined(PIOS_INCLUDE_ANNUNC)
136 #if defined(PIOS_INCLUDE_SPI)
137 if (
PIOS_SPI_Init(&pios_spi_gyro_accel_id, &pios_spi_gyro_accel_cfg)) {
142 #if defined(PIOS_INCLUDE_FLASH)
145 #ifdef PIOS_INCLUDE_WS2811
153 uint32_t num_partitions;
154 flash_partition_table = PIOS_BOARD_HW_DEFS_GetPartitionTable(bdinfo->
board_rev, &num_partitions);
159 #ifdef PIOS_INCLUDE_WS2811
169 HwSeppukuInitialize();
170 ModuleSettingsInitialize();
172 #if defined(PIOS_INCLUDE_RTC)
180 if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) == 0) {
196 if (boot_count < 3) {
201 HwSeppukuSetDefaults(HwSeppukuHandle(), 0);
202 ModuleSettingsSetDefaults(ModuleSettingsHandle(),0);
203 AlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_CRITICAL);
206 #if defined(PIOS_INCLUDE_USB)
211 bool usb_hid_present =
false;
212 bool usb_cdc_present =
false;
214 #if defined(PIOS_INCLUDE_USB_CDC)
218 usb_hid_present =
true;
219 usb_cdc_present =
true;
224 usb_hid_present =
true;
227 uintptr_t pios_usb_id;
230 #if defined(PIOS_INCLUDE_USB_CDC)
232 uint8_t hw_usb_vcpport;
234 HwSeppukuUSB_VCPPortGet(&hw_usb_vcpport);
236 if (!usb_cdc_present) {
238 hw_usb_vcpport = HWSEPPUKU_USB_VCPPORT_DISABLED;
245 #if defined(PIOS_INCLUDE_USB_HID)
247 uint8_t hw_usb_hidport;
248 HwSeppukuUSB_HIDPortGet(&hw_usb_hidport);
250 if (!usb_hid_present) {
252 hw_usb_hidport = HWSEPPUKU_USB_HIDPORT_DISABLED;
259 if (usb_hid_present || usb_cdc_present) {
265 HwSeppukuDSMxModeOptions hw_DSMxMode;
266 HwSeppukuDSMxModeGet(&hw_DSMxMode);
270 HwSeppukuRcvrPortGet(&hw_rcvrport);
272 PIOS_HAL_ConfigurePort(hw_rcvrport,
280 &pios_usart2_dsm_aux_cfg,
282 &pios_usart2_sbus_aux_cfg);
286 HwSeppukuUart1Get(&hw_uart1);
288 PIOS_HAL_ConfigurePort(hw_uart1,
296 &pios_usart1_dsm_aux_cfg,
302 HwSeppukuUart3Get(&hw_uart3);
304 PIOS_HAL_ConfigurePort(hw_uart3,
307 &pios_i2c_usart3_adapter_id,
308 &pios_i2c_usart3_adapter_cfg,
312 &pios_usart3_dsm_aux_cfg,
318 HwSeppukuUart6Get(&hw_uart6);
320 PIOS_HAL_ConfigurePort(hw_uart6,
328 &pios_usart6_dsm_aux_cfg,
332 uint8_t hw_outputconf;
333 HwSeppukuOutputConfigurationGet(&hw_outputconf);
335 switch (hw_outputconf) {
336 case HWSEPPUKU_OUTPUTCONFIGURATION_SIXCHANNELSUART4:
339 HwSeppukuUart4Get(&hw_uart4);
341 PIOS_HAL_ConfigurePort(hw_uart4,
349 &pios_uart4_dsm_aux_cfg,
353 #ifdef PIOS_INCLUDE_SERVO
358 #ifdef PIOS_INCLUDE_SERVO
364 #if defined(PIOS_INCLUDE_DMASHOT)
368 #ifdef PIOS_INCLUDE_WS2811
371 RGBLEDSettingsInitialize();
373 RGBLEDSettingsNumLedsGet(&num_leds);
383 #ifdef PIOS_INCLUDE_DAC
386 PIOS_HAL_ConfigureDAC(pios_dac);
394 #if defined(PIOS_INCLUDE_SPI)
396 #if defined(PIOS_INCLUDE_BMI160)
398 HwSeppukuBMI160FOCGet(&bmi160_foc);
400 bool do_foc = (bmi160_foc == HWSEPPUKU_BMI160FOC_DO_FOC);
408 bmi160_foc = HWSEPPUKU_BMI160FOC_DISABLED;
409 HwSeppukuBMI160FOCSet(&bmi160_foc);
414 #ifdef PIOS_INCLUDE_BMP280_SPI
419 }
else if (PIOS_BMP280_Test()) {
428 uint8_t hw_magnetometer;
429 HwSeppukuMagnetometerGet(&hw_magnetometer);
431 switch (hw_magnetometer) {
432 case HWSEPPUKU_MAGNETOMETER_NONE:
435 case HWSEPPUKU_MAGNETOMETER_INTERNAL:
436 #if defined(PIOS_INCLUDE_SPI) && defined(PIOS_INCLUDE_LIS3MDL)
449 #if defined(PIOS_INCLUDE_I2C)
451 if (pios_i2c_usart3_adapter_id) {
452 uint8_t hw_orientation;
453 HwSeppukuExtMagOrientationGet(&hw_orientation);
456 &pios_i2c_usart3_adapter_id,
457 &pios_i2c_usart3_adapter_cfg);
464 #endif // PIOS_INCLUDE_I2C
472 #if defined(PIOS_INCLUDE_ADC)
473 uintptr_t internal_adc_id;
478 #if defined(PIOS_INCLUDE_VIDEO)
484 OnScreenDisplaySettingsInitialize();
487 OnScreenDisplaySettingsOSDEnabledGet(&osd_state);
488 if (osd_state == ONSCREENDISPLAYSETTINGS_OSDENABLED_ENABLED) {
489 OSD_configure_bw_levels();
int32_t PIOS_Flash_Internal_Init(uintptr_t *flash_id, const struct pios_flash_internal_cfg *cfg)
int32_t PIOS_USB_DESC_HID_CDC_Init(void)
void PIOS_HAL_ConfigureCDC(HwSharedUSB_VCPPortOptions port_type, uintptr_t usb_id, const struct pios_usb_cdc_cfg *cdc_cfg)
int32_t PIOS_BMI160_Init(pios_spi_t spi_id, uint32_t slave_num, const struct pios_bmi160_cfg *cfg, bool do_foc)
Main PiOS header to include all the compiled in PiOS options.
int32_t PIOS_INTERNAL_ADC_Init(uintptr_t *internal_adc_id, const struct pios_internal_adc_cfg *cfg)
struct lis3mdl_dev * lis3mdl_dev_t
int PIOS_HAL_ConfigureExternalMag(HwSharedMagOptions mag, HwSharedMagOrientationOptions orientation, pios_i2c_t *i2c_id, const struct pios_i2c_adapter_cfg *i2c_cfg)
int32_t UAVObjSave(UAVObjHandle obj_handle, uint16_t instId)
int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity)
uintptr_t pios_uavo_settings_fs_id
Configuration structure for the BMP280 driver.
uint16_t PIOS_IAP_ReadBootCount(void)
int32_t PIOS_FLASHFS_Logfs_Init(uintptr_t *fs_id, const struct flashfs_logfs_cfg *cfg, enum pios_flash_partition_labels partition_label)
Initialize the flash object setting FS.
static const struct pios_tim_clock_cfg tim_8_cfg
const struct pios_board_info pios_board_info_blob
int PIOS_WS2811_init(ws2811_dev_t *dev_out, const struct pios_ws2811_cfg *cfg, int max_leds)
Allocate and initialise WS2811 device.
void PIOS_WDG_Clear(void)
Clear the watchdog timer.
int PIOS_DAC_init(dac_dev_t *dev_out, const struct pios_dac_cfg *cfg)
Allocate and initialise DAC device.
static const struct pios_tim_clock_cfg tim_4_cfg
uintptr_t pios_com_telem_serial_id
const struct pios_com_driver pios_usart_com_driver
pios_i2c_t external_i2c_adapter_id
static const struct pios_tim_clock_cfg tim_5_cfg
void PIOS_IAP_Init(void)
PIOS_IAP_Init - performs required initializations for iap module.
const struct pios_adc_driver pios_internal_adc_driver
int32_t PIOS_TIM_InitClock(const struct pios_tim_clock_cfg *cfg)
const struct pios_spi_cfg mask
uintptr_t pios_internal_adc_id
int32_t PIOS_SPI_Init(pios_spi_t *spi_dev, const struct pios_spi_cfg *cfg)
int32_t PIOS_ANNUNC_Init(const struct pios_annunc_cfg *cfg)
int32_t PIOS_SENSORS_Init()
Initialize the PIOS_SENSORS interface.
void PIOS_RTC_Init(const struct pios_rtc_cfg *cfg)
int32_t PIOS_BMP280_SPI_Init(const struct pios_bmp280_cfg *cfg, pios_spi_t spi_device, uint32_t spi_slave)
int32_t PIOS_USB_DESC_HID_ONLY_Init(void)
void PIOS_HAL_ConfigureHID(HwSharedUSB_HIDPortOptions port_type, uintptr_t usb_id, const struct pios_usb_hid_cfg *hid_cfg)
int32_t PIOS_Servo_Init(const struct pios_servo_cfg *cfg)
int32_t PIOS_LIS3MDL_SPI_Init(lis3mdl_dev_t *dev, pios_spi_t spi_id, uint32_t slave_mag, const struct pios_lis3mdl_cfg *cfg)
Initialize the LIS3MDL mag.
uintptr_t pios_com_openlog_logging_id
uintptr_t pios_com_telem_usb_id
static const struct pios_tim_clock_cfg tim_14_cfg
void PIOS_USBHOOK_Activate(void)
void PIOS_FLASH_register_partition_table(const struct pios_flash_partition partition_table[], uint8_t num_partitions)
Includes PiOS and core architecture components.
int32_t AlarmsClear(SystemAlarmsAlarmElem alarm)
void PIOS_WS2811_trigger_update(ws2811_dev_t dev)
Trigger an update of the LED strand.
int32_t PIOS_USB_Init(uintptr_t *usb_id, const struct pios_usb_cfg *cfg)
uint16_t PIOS_WDG_Init()
Initialize the watchdog timer for a specified timeout.
int32_t PIOS_ADC_Init(uintptr_t *adc_id, const struct pios_adc_driver *driver, uintptr_t lower_id)
void PIOS_IAP_WriteBootCount(uint16_t)
static const struct pios_tim_clock_cfg tim_3_cfg
void PIOS_HAL_CriticalError(uint32_t led_id, enum pios_hal_panic code)
Flash a blink code.
void PIOS_DMAShot_Init(const struct pios_dmashot_cfg *config)
Initializes the DMAShot driver by loading the configuration.
#define PIOS_Assert(test)
int32_t PIOS_USB_BOARD_DATA_Init(void)
void PIOS_RESET_Clear(void)
PIOS_RESET_Clear Does nothing on POSIX systems.
void PIOS_SENSORS_SetMissing(enum pios_sensor_type type)
Assert that an optional (non-accel/gyro), but expected sensor is missing.