38 #include "board_hw_defs.c"
43 #include <uavobjectsinit.h>
44 #include "hwquanton.h"
45 #include "manualcontrolsettings.h"
46 #include "modulesettings.h"
47 #include "rgbledsettings.h"
66 #if defined(PIOS_INCLUDE_ANNUNC)
72 #if defined(PIOS_INCLUDE_SPI)
76 if (
PIOS_SPI_Init(&pios_spi_gyro_accel_id, &pios_spi_gyro_accel_cfg)) {
82 #if defined(PIOS_INCLUDE_FLASH)
91 uint32_t num_partitions;
92 flash_partition_table = PIOS_BOARD_HW_DEFS_GetPartitionTable(bdinfo->
board_rev, &num_partitions);
103 HwQuantonInitialize();
104 ModuleSettingsInitialize();
106 #if defined(PIOS_INCLUDE_RTC)
114 if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) == 0) {
133 if (boot_count < 3) {
138 HwQuantonSetDefaults(HwQuantonHandle(), 0);
139 ModuleSettingsSetDefaults(ModuleSettingsHandle(),0);
140 AlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_CRITICAL);
143 #if defined(PIOS_INCLUDE_USB)
148 bool usb_hid_present =
false;
149 bool usb_cdc_present =
false;
151 #if defined(PIOS_INCLUDE_USB_CDC)
155 usb_hid_present =
true;
156 usb_cdc_present =
true;
161 usb_hid_present =
true;
164 uintptr_t pios_usb_id;
167 #if defined(PIOS_INCLUDE_USB_CDC)
169 uint8_t hw_usb_vcpport;
171 HwQuantonUSB_VCPPortGet(&hw_usb_vcpport);
173 if (!usb_cdc_present) {
175 hw_usb_vcpport = HWQUANTON_USB_VCPPORT_DISABLED;
182 #if defined(PIOS_INCLUDE_USB_HID)
184 uint8_t hw_usb_hidport;
185 HwQuantonUSB_HIDPortGet(&hw_usb_hidport);
187 if (!usb_hid_present) {
189 hw_usb_hidport = HWQUANTON_USB_HIDPORT_DISABLED;
196 if (usb_hid_present || usb_cdc_present) {
203 #if defined(PIOS_INCLUDE_I2C)
204 if (
PIOS_I2C_Init(&pios_i2c_internal_adapter_id, &pios_i2c_internal_adapter_cfg)) {
210 if (
AlarmsGet(SYSTEMALARMS_ALARM_I2C) == SYSTEMALARMS_ALARM_UNINITIALISED)
211 AlarmsSet(SYSTEMALARMS_ALARM_I2C, SYSTEMALARMS_ALARM_OK);
214 HwQuantonDSMxModeOptions hw_DSMxMode;
215 HwQuantonDSMxModeGet(&hw_DSMxMode);
219 HwQuantonUart1Get(&hw_uart1);
221 PIOS_HAL_ConfigurePort(hw_uart1,
224 &pios_i2c_usart1_adapter_id,
225 &pios_i2c_usart1_adapter_cfg,
229 &pios_usart1_dsm_aux_cfg,
235 HwQuantonUart2Get(&hw_uart2);
237 PIOS_HAL_ConfigurePort(hw_uart2,
245 &pios_usart2_dsm_aux_cfg,
247 &pios_usart2_sbus_aux_cfg);
251 HwQuantonUart3Get(&hw_uart3);
253 PIOS_HAL_ConfigurePort(hw_uart3,
256 &pios_i2c_usart3_adapter_id,
257 &pios_i2c_usart3_adapter_cfg,
261 &pios_usart3_dsm_aux_cfg,
267 HwQuantonUart4Get(&hw_uart4);
269 PIOS_HAL_ConfigurePort(hw_uart4,
277 &pios_usart4_dsm_aux_cfg,
283 HwQuantonUart5Get(&hw_uart5);
285 PIOS_HAL_ConfigurePort(hw_uart5,
293 &pios_usart5_dsm_aux_cfg,
299 HwQuantonInPortGet(&hw_inport);
302 case HWQUANTON_INPORT_DISABLED:
305 case HWQUANTON_INPORT_PWM:
306 PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PWM,
319 case HWQUANTON_INPORT_PWMADC:
320 PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PWM,
326 &pios_pwm_with_adc_cfg,
333 case HWQUANTON_INPORT_WS2811SERIALPPMADC:
335 PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PPM,
346 case HWQUANTON_INPORT_PPMSERIAL:
347 case HWQUANTON_INPORT_PPMSERIALADC:
348 case HWQUANTON_INPORT_SERIAL:
350 uint8_t hw_inportserial;
351 HwQuantonInPortSerialGet(&hw_inportserial);
353 PIOS_HAL_ConfigurePort(hw_inportserial,
354 &pios_usart_inportserial_cfg,
361 &pios_inportserial_dsm_aux_cfg,
366 if (hw_inport == HWQUANTON_INPORT_SERIAL)
369 if (hw_inport == HWQUANTON_INPORT_WS2811SERIALPPMADC)
374 case HWQUANTON_INPORT_PPM:
375 case HWQUANTON_INPORT_PPMADC:
376 case HWQUANTON_INPORT_PPMOUTPUTS:
377 case HWQUANTON_INPORT_PPMOUTPUTSADC:
378 PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PPM,
391 case HWQUANTON_INPORT_PPMPWM:
392 PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PPM,
404 PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PWM,
410 &pios_pwm_with_ppm_cfg,
417 case HWQUANTON_INPORT_PPMPWMADC:
418 PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PPM,
430 PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PWM,
436 &pios_pwm_with_ppm_with_adc_cfg,
444 #ifndef PIOS_DEBUG_ENABLE_DEBUG_PINS
446 case HWQUANTON_INPORT_DISABLED:
447 case HWQUANTON_INPORT_PWM:
448 case HWQUANTON_INPORT_PWMADC:
449 case HWQUANTON_INPORT_PPM:
450 case HWQUANTON_INPORT_PPMADC:
451 case HWQUANTON_INPORT_PPMPWM:
452 case HWQUANTON_INPORT_PPMPWMADC:
453 case HWQUANTON_INPORT_WS2811SERIALPPMADC:
455 #ifdef PIOS_INCLUDE_SERVO
459 case HWQUANTON_INPORT_PPMOUTPUTS:
460 #ifdef PIOS_INCLUDE_SERVO
464 case HWQUANTON_INPORT_OUTPUTS:
465 #ifdef PIOS_INCLUDE_SERVO
469 case HWQUANTON_INPORT_PPMOUTPUTSADC:
470 #ifdef PIOS_INCLUDE_SERVO
474 case HWQUANTON_INPORT_OUTPUTSADC:
475 #ifdef PIOS_INCLUDE_SERVO
484 #ifdef PIOS_INCLUDE_WS2811
485 RGBLEDSettingsInitialize();
487 if (hw_inport == HWQUANTON_INPORT_WS2811SERIALPPMADC) {
490 RGBLEDSettingsNumLedsGet(&temp);
508 #if defined(PIOS_INCLUDE_MPU)
513 HwQuantonGyroRangeOptions hw_gyro_range;
514 HwQuantonGyroRangeGet(&hw_gyro_range);
515 switch(hw_gyro_range) {
516 case HWQUANTON_GYRORANGE_250:
519 case HWQUANTON_GYRORANGE_500:
522 case HWQUANTON_GYRORANGE_1000:
525 case HWQUANTON_GYRORANGE_2000:
530 HwQuantonAccelRangeOptions hw_accel_range;
531 HwQuantonAccelRangeGet(&hw_accel_range);
532 switch(hw_accel_range) {
533 case HWQUANTON_ACCELRANGE_2G:
536 case HWQUANTON_ACCELRANGE_4G:
539 case HWQUANTON_ACCELRANGE_8G:
542 case HWQUANTON_ACCELRANGE_16G:
548 HwQuantonMPU6000DLPFOptions hw_mpu_dlpf;
549 HwQuantonMPU6000DLPFGet(&hw_mpu_dlpf);
550 uint16_t bandwidth = \
551 (hw_mpu_dlpf == HWQUANTON_MPU6000DLPF_188) ? 188 : \
552 (hw_mpu_dlpf == HWQUANTON_MPU6000DLPF_98) ? 98 : \
553 (hw_mpu_dlpf == HWQUANTON_MPU6000DLPF_42) ? 42 : \
554 (hw_mpu_dlpf == HWQUANTON_MPU6000DLPF_20) ? 20 : \
555 (hw_mpu_dlpf == HWQUANTON_MPU6000DLPF_10) ? 10 : \
556 (hw_mpu_dlpf == HWQUANTON_MPU6000DLPF_5) ? 5 : \
561 #if defined(PIOS_INCLUDE_I2C)
565 uint8_t hw_magnetometer;
566 HwQuantonMagnetometerGet(&hw_magnetometer);
568 switch (hw_magnetometer) {
569 case HWQUANTON_MAGNETOMETER_NONE:
572 case HWQUANTON_MAGNETOMETER_INTERNAL:
573 #if defined(PIOS_INCLUDE_HMC5883)
574 if ((
PIOS_HMC5883_Init(pios_i2c_internal_adapter_id, &pios_hmc5883_internal_cfg) != 0) ||
584 HwQuantonExtMagPortOptions hw_mag_port;
585 HwQuantonExtMagPortGet(&hw_mag_port);
588 const void *i2c_mag_cfg = NULL;
589 switch (hw_mag_port) {
590 case HWQUANTON_EXTMAGPORT_UART1:
591 if (hw_uart1 == HWSHARED_PORTTYPES_I2C) {
592 i2c_mag_id = pios_i2c_usart1_adapter_id;
593 i2c_mag_cfg = &pios_i2c_usart1_adapter_cfg;
596 case HWQUANTON_EXTMAGPORT_UART3:
597 if (hw_uart3 == HWSHARED_PORTTYPES_I2C) {
598 i2c_mag_id = pios_i2c_usart3_adapter_id;
599 i2c_mag_cfg = &pios_i2c_usart3_adapter_cfg;
604 if (i2c_mag_id && i2c_mag_cfg) {
605 uint8_t hw_orientation;
606 HwQuantonExtMagOrientationGet(&hw_orientation);
609 &i2c_mag_id, i2c_mag_cfg);
620 #if defined(PIOS_INCLUDE_MS5611)
622 || (PIOS_MS5611_Test() != 0))
631 #if defined(PIOS_INCLUDE_ADC)
632 if (hw_inport == HWQUANTON_INPORT_OUTPUTSADC ||
633 hw_inport == HWQUANTON_INPORT_PPMADC ||
634 hw_inport == HWQUANTON_INPORT_PPMOUTPUTSADC ||
635 hw_inport == HWQUANTON_INPORT_PPMPWMADC ||
636 hw_inport == HWQUANTON_INPORT_PPMSERIALADC ||
637 hw_inport == HWQUANTON_INPORT_PWMADC ||
638 hw_inport == HWQUANTON_INPORT_WS2811SERIALPPMADC)
640 uintptr_t internal_adc_id;
648 GPIO_InitTypeDef GPIO_InitStructure;
649 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
650 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
651 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
652 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
653 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
654 GPIO_Init(GPIOC, &GPIO_InitStructure);
655 GPIO_ResetBits(GPIOC, GPIO_Pin_15);
658 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
659 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
660 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
661 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
662 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
663 GPIO_Init(GPIOA, &GPIO_InitStructure);
664 GPIO_ResetBits(GPIOA, GPIO_Pin_4);
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_HMC5883_Test(void)
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
const struct pios_board_info pios_board_info_blob
struct pios_mpu_dev * pios_mpu_dev_t
int PIOS_WS2811_init(ws2811_dev_t *dev_out, const struct pios_ws2811_cfg *cfg, int max_leds)
Allocate and initialise WS2811 device.
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.
int32_t PIOS_MPU_SPI_Init(pios_mpu_dev_t *dev, pios_spi_t spi_id, uint32_t slave_num, const struct pios_mpu_cfg *cfg)
Initialize the MPU-xxxx 6/9-axis sensor on SPI.
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
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.
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)
uintptr_t pios_internal_adc_id
struct pios_i2c_adapter * pios_i2c_t
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)
static const struct pios_tim_clock_cfg tim_1_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
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)
int32_t PIOS_HMC5883_Init(pios_i2c_t i2c_id, const struct pios_hmc5883_cfg *cfg)
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)
int32_t PIOS_MS5611_Init(const struct pios_ms5611_cfg *cfg, pios_i2c_t i2c_device)
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.
static const struct pios_tim_clock_cfg tim_2_cfg
static const struct pios_tim_clock_cfg tim_10_cfg
#define PIOS_Assert(test)
int32_t PIOS_DELAY_WaitmS(uint32_t mS)
int32_t PIOS_MPU_SetGyroRange(enum pios_mpu_gyro_range range)
int32_t PIOS_USB_BOARD_DATA_Init(void)
static const struct pios_tim_clock_cfg tim_11_cfg
SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm)
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.