38 #include "board_hw_defs.c"
43 #include <uavobjectsinit.h>
45 #include "modulesettings.h"
46 #include "manualcontrolsettings.h"
47 #include "onscreendisplaysettings.h"
59 #if defined(PIOS_INCLUDE_VIDEO)
60 void OSD_configure_bw_levels(
void)
62 GPIO_InitTypeDef GPIO_InitStructure;
63 TIM_OCInitTypeDef TIM_OCInitStructure;
64 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
68 RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
71 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
74 GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_TIM1);
75 GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_TIM1);
78 GPIO_StructInit(&GPIO_InitStructure);
79 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_10;
80 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
81 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
82 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
83 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
84 GPIO_Init(GPIOA, &GPIO_InitStructure);
88 TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
89 TIM_TimeBaseStructure.TIM_Prescaler = (
PIOS_SYSCLK / 25500000) - 1;
90 TIM_TimeBaseStructure.TIM_Period = 255;
91 TIM_TimeBaseStructure.TIM_ClockDivision = 0;
92 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
93 TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
96 TIM_ARRPreloadConfig(TIM1, ENABLE);
99 TIM_OCStructInit(&TIM_OCInitStructure);
100 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
101 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
102 TIM_OCInitStructure.TIM_Pulse = 90;
103 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
106 TIM_OC1Init(TIM1, &TIM_OCInitStructure);
107 TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
108 TIM_OC3Init(TIM1, &TIM_OCInitStructure);
109 TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Enable);
112 TIM_CtrlPWMOutputs(TIM1, ENABLE);
115 TIM_Cmd(TIM1, ENABLE);
130 bool use_rxport_usart =
false;
132 #if defined(PIOS_INCLUDE_ANNUNC)
136 #if defined(PIOS_INCLUDE_I2C)
137 if (
PIOS_I2C_Init(&pios_i2c_internal_id, &pios_i2c_internal_cfg)) {
144 #if defined(PIOS_INCLUDE_SPI)
145 if (
PIOS_SPI_Init(&pios_spi_flash_id, &pios_spi_flash_cfg)) {
150 #if defined(PIOS_INCLUDE_FLASH)
166 ModuleSettingsInitialize();
168 #if defined(PIOS_INCLUDE_RTC)
176 if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) == 0) {
194 if (boot_count < 3) {
199 HwBrainSetDefaults(HwBrainHandle(), 0);
200 ModuleSettingsSetDefaults(ModuleSettingsHandle(),0);
201 AlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_CRITICAL);
204 #if defined(PIOS_INCLUDE_USB)
209 bool usb_hid_present =
false;
210 bool usb_cdc_present =
false;
212 #if defined(PIOS_INCLUDE_USB_CDC)
216 usb_hid_present =
true;
217 usb_cdc_present =
true;
222 usb_hid_present =
true;
225 uintptr_t pios_usb_id;
228 #if defined(PIOS_INCLUDE_USB_CDC)
230 uint8_t hw_usb_vcpport;
232 HwBrainUSB_VCPPortGet(&hw_usb_vcpport);
234 if (!usb_cdc_present) {
236 hw_usb_vcpport = HWBRAIN_USB_VCPPORT_DISABLED;
243 #if defined(PIOS_INCLUDE_USB_HID)
245 uint8_t hw_usb_hidport;
246 HwBrainUSB_HIDPortGet(&hw_usb_hidport);
248 if (!usb_hid_present) {
250 hw_usb_hidport = HWBRAIN_USB_HIDPORT_DISABLED;
257 if (usb_hid_present || usb_cdc_present) {
263 HwBrainDSMxModeOptions hw_DSMxMode;
264 HwBrainDSMxModeGet(&hw_DSMxMode);
268 HwBrainMainPortGet(&hw_mainport);
270 PIOS_HAL_ConfigurePort(hw_mainport,
278 &pios_mainport_dsm_aux_cfg,
280 &pios_mainport_sbus_aux_cfg);
284 HwBrainFlxPortGet(&hw_flxport);
286 PIOS_HAL_ConfigurePort(hw_flxport,
294 &pios_flxport_dsm_aux_cfg,
300 HwBrainRxPortGet(&hw_rxport);
303 case HWBRAIN_RXPORT_DISABLED:
306 case HWBRAIN_RXPORT_PWM:
307 PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PWM,
320 case HWBRAIN_RXPORT_PPM:
321 case HWBRAIN_RXPORT_PPMOUTPUTS:
322 PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PPM,
335 case HWBRAIN_RXPORT_UART:
336 case HWBRAIN_RXPORT_UARTOUTPUTS:
337 use_rxport_usart =
true;
340 case HWBRAIN_RXPORT_PPMUART:
341 case HWBRAIN_RXPORT_PPMUARTOUTPUTS:
342 use_rxport_usart =
true;
344 PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PPM,
359 if (use_rxport_usart) {
360 uint8_t hw_rxportusart;
361 HwBrainRxPortUsartGet(&hw_rxportusart);
363 PIOS_HAL_ConfigurePort(hw_rxportusart,
364 &pios_rxportusart_cfg,
371 &pios_rxportusart_dsm_aux_cfg,
376 #if defined(PIOS_INCLUDE_SERVO) & defined(PIOS_INCLUDE_DMASHOT)
378 #endif // defined(PIOS_INCLUDE_DMASHOT)
380 #ifndef PIOS_DEBUG_ENABLE_DEBUG_PINS
382 case HWBRAIN_RXPORT_DISABLED:
383 case HWBRAIN_RXPORT_PWM:
384 case HWBRAIN_RXPORT_PPM:
385 case HWBRAIN_RXPORT_UART:
386 case HWBRAIN_RXPORT_PPMUART:
388 #ifdef PIOS_INCLUDE_SERVO
392 case HWBRAIN_RXPORT_PPMOUTPUTS:
393 #ifdef PIOS_INCLUDE_SERVO
397 case HWBRAIN_RXPORT_PPMUARTOUTPUTS:
398 case HWBRAIN_RXPORT_UARTOUTPUTS:
399 #ifdef PIOS_INCLUDE_SERVO
403 case HWBRAIN_RXPORT_OUTPUTS:
404 #ifdef PIOS_INCLUDE_SERVO
413 #ifdef PIOS_INCLUDE_DAC
416 PIOS_HAL_ConfigureDAC(pios_dac);
426 #if defined(PIOS_INCLUDE_MS5611)
428 || (PIOS_MS5611_Test() != 0))
435 uint8_t hw_magnetometer;
436 HwBrainMagnetometerGet(&hw_magnetometer);
437 switch (hw_magnetometer) {
438 case HWBRAIN_MAGNETOMETER_NONE:
442 case HWBRAIN_MAGNETOMETER_INTERNAL:
450 if (hw_flxport == HWSHARED_PORTTYPES_I2C) {
451 uint8_t hw_orientation;
452 HwBrainExtMagOrientationGet(&hw_orientation);
455 &pios_i2c_flexi_id, &pios_i2c_flexi_cfg);
462 #if defined(PIOS_INCLUDE_MPU)
463 uint8_t hw_mpu9250_dlpf;
464 HwBrainMPU9250GyroLPFGet(&hw_mpu9250_dlpf);
465 uint16_t gyro_lpf = \
466 (hw_mpu9250_dlpf == HWBRAIN_MPU9250GYROLPF_184) ? 184 : \
467 (hw_mpu9250_dlpf == HWBRAIN_MPU9250GYROLPF_92) ? 92 : \
468 (hw_mpu9250_dlpf == HWBRAIN_MPU9250GYROLPF_41) ? 41 : \
469 (hw_mpu9250_dlpf == HWBRAIN_MPU9250GYROLPF_20) ? 20 : \
470 (hw_mpu9250_dlpf == HWBRAIN_MPU9250GYROLPF_10) ? 10 : \
471 (hw_mpu9250_dlpf == HWBRAIN_MPU9250GYROLPF_5) ? 5 : \
474 HwBrainMPU9250AccelLPFGet(&hw_mpu9250_dlpf);
475 uint16_t accel_lpf = \
476 (hw_mpu9250_dlpf == HWBRAIN_MPU9250ACCELLPF_460) ? 460 : \
477 (hw_mpu9250_dlpf == HWBRAIN_MPU9250ACCELLPF_184) ? 184 : \
478 (hw_mpu9250_dlpf == HWBRAIN_MPU9250ACCELLPF_92) ? 92 : \
479 (hw_mpu9250_dlpf == HWBRAIN_MPU9250ACCELLPF_41) ? 41 : \
480 (hw_mpu9250_dlpf == HWBRAIN_MPU9250ACCELLPF_20) ? 20 : \
481 (hw_mpu9250_dlpf == HWBRAIN_MPU9250ACCELLPF_10) ? 10 : \
482 (hw_mpu9250_dlpf == HWBRAIN_MPU9250ACCELLPF_5) ? 5 : \
495 uint8_t hw_gyro_range;
496 HwBrainGyroFullScaleGet(&hw_gyro_range);
497 switch (hw_gyro_range) {
498 case HWBRAIN_GYROFULLSCALE_250:
501 case HWBRAIN_GYROFULLSCALE_500:
504 case HWBRAIN_GYROFULLSCALE_1000:
507 case HWBRAIN_GYROFULLSCALE_2000:
512 uint8_t hw_accel_range;
513 HwBrainAccelFullScaleGet(&hw_accel_range);
514 switch (hw_accel_range) {
515 case HWBRAIN_ACCELFULLSCALE_2G:
518 case HWBRAIN_ACCELFULLSCALE_4G:
521 case HWBRAIN_ACCELFULLSCALE_8G:
524 case HWBRAIN_ACCELFULLSCALE_16G:
532 #if defined(PIOS_INCLUDE_ADC)
533 uintptr_t internal_adc_id;
538 #if defined(PIOS_INCLUDE_VIDEO)
544 OnScreenDisplaySettingsInitialize();
547 OnScreenDisplaySettingsOSDEnabledGet(&osd_state);
548 if (osd_state == ONSCREENDISPLAYSETTINGS_OSDENABLED_ENABLED) {
549 OSD_configure_bw_levels();
int32_t PIOS_MPU_I2C_Init(pios_mpu_dev_t *dev, pios_i2c_t i2c_id, const struct pios_mpu_cfg *cfg)
Initialize the MPU-xxxx 6/9-axis sensor on I2C.
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)
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)
int32_t PIOS_I2C_CheckClear(pios_i2c_t i2c_id)
int32_t PIOS_Flash_Jedec_Init(uintptr_t *flash_id, pios_spi_t spi_id, uint32_t slave_num, const struct pios_flash_jedec_cfg *cfg)
#define PIOS_DEBUG_Assert(test)
int PIOS_HAL_ConfigureExternalMag(HwSharedMagOptions mag, HwSharedMagOrientationOptions orientation, pios_i2c_t *i2c_id, const struct pios_i2c_adapter_cfg *i2c_cfg)
int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity)
uintptr_t pios_uavo_settings_fs_id
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
struct pios_mpu_dev * pios_mpu_dev_t
Configuration structure for the MS5611 driver.
int32_t PIOS_I2C_Init(pios_i2c_t *i2c_id, const char *path)
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.
void PIOS_DEBUG_Init(const struct pios_tim_channel *channels, uint8_t num_channels)
uintptr_t pios_com_telem_serial_id
const struct pios_com_driver pios_usart_com_driver
static const struct pios_tim_clock_cfg tim_5_cfg
void PIOS_IAP_Init(void)
PIOS_IAP_Init - performs required initializations for iap module.
int32_t PIOS_MPU_SetAccelRange(enum pios_mpu_accel_range range)
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_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)
void PIOS_MPU_SetGyroBandwidth(uint16_t bandwidth)
Sets the bandwidth desired from the gyro. The driver will automatically select the lowest bandwidth l...
uintptr_t pios_com_openlog_logging_id
uintptr_t pios_com_telem_usb_id
void PIOS_MPU_SetAccelBandwidth(uint16_t bandwidth)
Sets the bandwidth desired from the accelerometer. The driver will automatically select the lowest ba...
uintptr_t pios_com_logging_id
static const struct pios_tim_clock_cfg tim_12_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)
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)
const struct pios_flash_partition pios_flash_partition_table[]
void PIOS_IAP_WriteBootCount(uint16_t)
int32_t PIOS_MS5611_Init(const struct pios_ms5611_cfg *cfg, pios_i2c_t i2c_device)
void PIOS_HAL_CriticalError(uint32_t led_id, enum pios_hal_panic code)
Flash a blink code.
int32_t AlarmsInitialize(void)
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_MPU_SetGyroRange(enum pios_mpu_gyro_range range)
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.