42 #include "board_hw_defs.c"
47 #include <uavobjectsinit.h>
48 #include "hwrevolution.h"
49 #include "manualcontrolsettings.h"
50 #include "modulesettings.h"
54 #if defined(PIOS_INCLUDE_WS2811)
55 #include "rgbledsettings.h"
58 #if defined(PIOS_INCLUDE_DEBUG_CONSOLE)
59 #define PIOS_COM_DEBUGCONSOLE_TX_BUF_LEN 40
67 #ifdef PIOS_INCLUDE_MAX7456
80 bool use_rxport_usart =
false;
83 bool is_modified_clone =
false;
87 #if defined(PIOS_INCLUDE_ANNUNC)
100 if (
PIOS_SPI_Init(&pios_spi_telem_flash_id, &pios_spi_telem_flash_cfg)) {
104 #if defined(PIOS_INCLUDE_FLASH)
106 bool flash_chip_ok =
false;
109 1, &flash_chip_cfgs[
i]) == 0) {
110 flash_chip_ok =
true;
111 is_modified_clone = i > 0;
116 if (!flash_chip_ok) {
119 is_modified_clone =
true;
124 pios_external_flash_id = 0;
131 uint32_t num_partitions;
133 flash_partition_table = PIOS_BOARD_HW_DEFS_GetPartitionTable(bdinfo->
board_rev, &num_partitions);
144 HwRevolutionInitialize();
145 ModuleSettingsInitialize();
147 #if defined(PIOS_INCLUDE_RTC)
154 if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) == 0) {
171 if (boot_count < 3) {
176 HwRevolutionSetDefaults(HwRevolutionHandle(), 0);
177 ModuleSettingsSetDefaults(ModuleSettingsHandle(),0);
178 AlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_CRITICAL);
184 #if defined(PIOS_INCLUDE_USB)
189 bool usb_hid_present =
false;
190 bool usb_cdc_present =
false;
192 #if defined(PIOS_INCLUDE_USB_CDC)
196 usb_hid_present =
true;
197 usb_cdc_present =
true;
202 usb_hid_present =
true;
205 uintptr_t pios_usb_id;
208 #if defined(PIOS_INCLUDE_USB_CDC)
209 uint8_t hw_usb_vcpport;
211 HwRevolutionUSB_VCPPortGet(&hw_usb_vcpport);
217 #if defined(PIOS_INCLUDE_USB_HID)
219 uint8_t hw_usb_hidport;
220 HwRevolutionUSB_HIDPortGet(&hw_usb_hidport);
222 if (!usb_hid_present) {
224 hw_usb_hidport = HWREVOLUTION_USB_HIDPORT_DISABLED;
230 if (usb_hid_present || usb_cdc_present) {
237 #if defined(PIOS_INCLUDE_I2C)
238 if (
PIOS_I2C_Init(&pios_i2c_mag_pressure_adapter_id, &pios_i2c_mag_pressure_adapter_cfg)) {
239 if (!is_modified_clone) {
243 if (
AlarmsGet(SYSTEMALARMS_ALARM_I2C) == SYSTEMALARMS_ALARM_UNINITIALISED) {
244 AlarmsSet(SYSTEMALARMS_ALARM_I2C, SYSTEMALARMS_ALARM_OK);
247 #endif // PIOS_INCLUDE_I2C
249 HwRevolutionDSMxModeOptions hw_DSMxMode;
250 HwRevolutionDSMxModeGet(&hw_DSMxMode);
255 HwRevolutionMainPortGet(&hw_mainport);
257 PIOS_HAL_ConfigurePort(hw_mainport,
266 hw_DSMxMode >= HWREVOLUTION_DSMXMODE_BIND3PULSES ? HWREVOLUTION_DSMXMODE_AUTODETECT : hw_DSMxMode ,
270 uint8_t hw_flexiport;
271 HwRevolutionFlexiPortGet(&hw_flexiport);
273 PIOS_HAL_ConfigurePort(hw_flexiport,
276 &pios_i2c_flexiport_adapter_id,
277 &pios_i2c_flexiport_adapter_cfg,
287 HwRevolutionRxPortGet(&hw_rxport);
290 case HWREVOLUTION_RXPORT_DISABLED:
293 case HWREVOLUTION_RXPORT_PWM:
294 PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PWM,
307 case HWREVOLUTION_RXPORT_PPM:
308 case HWREVOLUTION_RXPORT_PPMOUTPUTS:
309 PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PPM,
322 case HWREVOLUTION_RXPORT_UART:
323 use_rxport_usart =
true;
326 case HWREVOLUTION_RXPORT_PPMUART:
327 use_rxport_usart =
true;
329 PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PPM,
344 if (use_rxport_usart) {
345 uint8_t hw_rxportusart;
346 HwRevolutionRxPortUsartGet(&hw_rxportusart);
348 PIOS_HAL_ConfigurePort(hw_rxportusart,
349 &pios_rxportusart_cfg,
356 &pios_rxportusart_dsm_aux_cfg,
361 #ifndef PIOS_DEBUG_ENABLE_DEBUG_PINS
363 case HWREVOLUTION_RXPORT_DISABLED:
364 case HWREVOLUTION_RXPORT_PWM:
365 case HWREVOLUTION_RXPORT_PPM:
366 case HWREVOLUTION_RXPORT_UART:
367 case HWREVOLUTION_RXPORT_PPMUART:
369 #ifdef PIOS_INCLUDE_SERVO
373 case HWREVOLUTION_RXPORT_PPMOUTPUTS:
374 #ifdef PIOS_INCLUDE_SERVO
378 case HWREVOLUTION_RXPORT_OUTPUTS:
379 #ifdef PIOS_INCLUDE_SERVO
388 HwRevolutionData hwRevoMini;
389 HwRevolutionGet(&hwRevoMini);
391 uint8_t hw_spiperiph;
393 HwRevolutionSPIPeripheralGet(&hw_spiperiph);
395 switch (hw_spiperiph) {
399 case HWREVOLUTION_SPIPERIPHERAL_DISABLED:
402 #ifdef PIOS_INCLUDE_MAX7456
403 case HWREVOLUTION_SPIPERIPHERAL_MAX7456OSD:
411 #ifdef PIOS_INCLUDE_OPENLRS
412 case HWREVOLUTION_SPIPERIPHERAL_RADIO:
414 const struct pios_openlrs_cfg *openlrs_cfg =PIOS_BOARD_HW_DEFS_GetOpenLRSCfg(bdinfo->
board_rev);
416 PIOS_HAL_ConfigureRFM22B(pios_spi_telem_flash_id,
419 hwRevoMini.MaxRfPower,
426 #ifdef PIOS_INCLUDE_WS2811
429 RGBLEDSettingsInitialize();
431 RGBLEDSettingsNumLedsGet(&num_leds);
434 switch (hwRevoMini.WS2811Pin) {
436 case HWREVOLUTION_WS2811PIN_DISABLED:
439 case HWREVOLUTION_WS2811PIN_PB12INPORTPIN3:
441 &pios_ws2811_cfg_pb12,
446 case HWREVOLUTION_WS2811PIN_PD2OMNIBUSF4LEDPORT:
447 if (hw_spiperiph == HWREVOLUTION_SPIPERIPHERAL_RADIO) {
453 &pios_ws2811_cfg_pd2,
458 case HWREVOLUTION_WS2811PIN_PB6OMNIBUSF4V2LEDPORT:
460 &pios_ws2811_cfg_pb6,
465 case HWREVOLUTION_WS2811PIN_PA0SERVOOUT6:
469 &pios_ws2811_cfg_pa0,
484 #if defined(PIOS_INCLUDE_MPU)
489 HwRevolutionGyroRangeOptions hw_gyro_range;
490 HwRevolutionGyroRangeGet(&hw_gyro_range);
491 switch(hw_gyro_range) {
492 case HWREVOLUTION_GYRORANGE_250:
495 case HWREVOLUTION_GYRORANGE_500:
498 case HWREVOLUTION_GYRORANGE_1000:
501 case HWREVOLUTION_GYRORANGE_2000:
506 HwRevolutionAccelRangeOptions hw_accel_range;
507 HwRevolutionAccelRangeGet(&hw_accel_range);
508 switch(hw_accel_range) {
509 case HWREVOLUTION_ACCELRANGE_2G:
512 case HWREVOLUTION_ACCELRANGE_4G:
515 case HWREVOLUTION_ACCELRANGE_8G:
518 case HWREVOLUTION_ACCELRANGE_16G:
524 HwRevolutionMPU6000DLPFOptions hw_mpu_dlpf;
525 HwRevolutionMPU6000DLPFGet(&hw_mpu_dlpf);
526 uint16_t bandwidth = \
527 (hw_mpu_dlpf == HWREVOLUTION_MPU6000DLPF_188) ? 188 : \
528 (hw_mpu_dlpf == HWREVOLUTION_MPU6000DLPF_98) ? 98 : \
529 (hw_mpu_dlpf == HWREVOLUTION_MPU6000DLPF_42) ? 42 : \
530 (hw_mpu_dlpf == HWREVOLUTION_MPU6000DLPF_20) ? 20 : \
531 (hw_mpu_dlpf == HWREVOLUTION_MPU6000DLPF_10) ? 10 : \
532 (hw_mpu_dlpf == HWREVOLUTION_MPU6000DLPF_5) ? 5 : \
537 #if defined(PIOS_INCLUDE_I2C)
540 uint8_t hw_magnetometer;
541 HwRevolutionMagnetometerGet(&hw_magnetometer);
543 if (!pios_i2c_mag_pressure_adapter_id) {
544 hw_magnetometer = HWREVOLUTION_MAGNETOMETER_NONE;
547 switch (hw_magnetometer) {
548 case HWREVOLUTION_MAGNETOMETER_NONE:
551 case HWREVOLUTION_MAGNETOMETER_INTERNAL:
552 #if defined(PIOS_INCLUDE_HMC5883)
555 if (!is_modified_clone) {
564 if (hw_flexiport == HWSHARED_PORTTYPES_I2C) {
565 uint8_t hw_orientation;
566 HwRevolutionExtMagOrientationGet(&hw_orientation);
569 &pios_i2c_flexiport_adapter_id, &pios_i2c_flexiport_adapter_cfg);
579 #if defined(PIOS_INCLUDE_MS5611)
581 if (!is_modified_clone) {
590 #if defined(PIOS_INCLUDE_BMP280) && !defined(PIOS_EXCLUDE_BMP280_I2C)
592 if (is_modified_clone &&
593 (pios_i2c_mag_pressure_adapter_id) &&
596 pios_i2c_mag_pressure_adapter_id);
602 #ifdef PIOS_INCLUDE_SPI
603 #ifdef PIOS_INCLUDE_BMP280_SPI
605 if ((!flash_chip_ok) &&
609 pios_spi_telem_flash_id, 1);
614 #if defined(PIOS_INCLUDE_ADC)
615 uintptr_t internal_adc_id;
620 GPIO_Init(pios_current_sonar_pin.gpio, &pios_current_sonar_pin.init);
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_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)
uintptr_t pios_com_debug_id
#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)
static const struct pios_usart_cfg pios_usart_main_cfg
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
struct pios_mpu_dev * pios_mpu_dev_t
struct max7456_dev_s * max7456_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)
static const struct pios_tim_clock_cfg tim_4_cfg
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)
void PIOS_Servo_DisableChannel(int channel)
const struct pios_adc_driver pios_internal_adc_driver
bool PIOS_SENSORS_IsRegistered(enum pios_sensor_type type)
Checks if a sensor type is registered with the PIOS_SENSORS interface.
int32_t PIOS_TIM_InitClock(const struct pios_tim_clock_cfg *cfg)
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)
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_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)
void PIOS_MPU_SetGyroBandwidth(uint16_t bandwidth)
Sets the bandwidth desired from the gyro. The driver will automatically select the lowest bandwidth l...
static const struct pios_usart_cfg pios_usart_flexi_cfg
uintptr_t pios_com_openlog_logging_id
int32_t PIOS_BMP280_Init(const struct pios_bmp280_cfg *cfg, pios_i2c_t i2c_device)
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_9_cfg
static const struct pios_tim_clock_cfg tim_10_cfg
#define PIOS_Assert(test)
int PIOS_MAX7456_init(max7456_dev_t *dev_out, pios_spi_t spi_handle, uint32_t slave_idx)
Allocate and initialise MAX7456 device.
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.
#define PIOS_LED_HEARTBEAT
void PIOS_SENSORS_SetMissing(enum pios_sensor_type type)
Assert that an optional (non-accel/gyro), but expected sensor is missing.