Skip to content

Commit

Permalink
RMT
Browse files Browse the repository at this point in the history
  • Loading branch information
radityankn committed Sep 21, 2023
1 parent 49a44aa commit 53272a9
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 46 deletions.
9 changes: 7 additions & 2 deletions libraries/AP_HAL_ESP32/RCOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include <AP_Math/AP_Math.h>
#include <AP_BoardConfig/AP_BoardConfig.h>

#if AP_SBUSOUTPUT_ENABLED
#include <AP_SBusOut/AP_SBusOut.h>
#endif

#include "driver/rtc_io.h"
#include "driver/gpio.h"

Expand Down Expand Up @@ -109,7 +113,6 @@ void RCOutput::init()
mcpwm_init(unit, timer, &pwm_config);
mcpwm_start(unit, timer);
}

_initialized = true;
}

Expand Down Expand Up @@ -227,7 +230,9 @@ void RCOutput::push()
write_int(i, period_us);
}
}

#if AP_SBUSOUTPUT_ENABLED
sbus->update();
#endif
_corked = false;
}

Expand Down
59 changes: 31 additions & 28 deletions libraries/AP_HAL_ESP32/boards/esp32empty.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,42 +71,43 @@
#define DEFAULT_SERIAL9_BAUD (115200/1000)

//IMUs
#define INS_AUX_INSTANCE 2
#define INS_AUX_INSTANCE 3
#define HAL_INS_DEFAULT HAL_INS_MPU9250_SPI
#define HAL_INS_MPU9250_NAME "mpu9250"
#define HAL_INS_BMI160_NAME "bmi160"
#define HAL_INS_PROBE_LIST PROBE_IMU_SPI(Invensense, HAL_INS_MPU9250_NAME, ROTATION_YAW_90); \
PROBE_IMU_SPI(BMI160, HAL_INS_BMI160_NAME, ROTATION_ROLL_180)
#define HAL_INS_MPU6500_NAME "mpu6500"
#define HAL_INS_PROBE_LIST PROBE_IMU_SPI(Invensense, HAL_INS_MPU9250_NAME, ROTATION_NONE);\
PROBE_IMU_SPI(Invensense, HAL_INS_MPU6500_NAME, ROTATION_NONE);
/*
#define HAL_INS_PROBE_LIST PROBE_IMU_SPI(Invensense, HAL_INS_MPU9250_NAME, ROTATION_NONE); \
PROBE_IMU_SPI(BMI160, HAL_INS_BMI160_NAME, ROTATION_ROLL_180_YAW_90)
*/

//I2C Buses
#define HAL_ESP32_I2C_BUSES {.port=I2C_NUM_0, .sda=GPIO_NUM_21, .scl=GPIO_NUM_22, .speed=400*KHZ, .internal=true, .soft=true}

#define HAL_ESP32_I2C_BUSES {.port=I2C_NUM_0, .sda=GPIO_NUM_32, .scl=GPIO_NUM_13, .speed=400*KHZ, .internal=true}
// {.port=I2C_NUM_1, .sda=GPIO_NUM_15, .scl=GPIO_NUM_17, .speed=400*KHZ, .internal=true}
//SPI Buses
#define HAL_ESP32_SPI_BUSES {.host=VSPI_HOST, .dma_ch=1, .mosi=GPIO_NUM_23, .miso=GPIO_NUM_19, .sclk=GPIO_NUM_18} // mosi/miso swapped
#define HAL_ESP32_SPI_BUSES {.host=VSPI_HOST, .dma_ch=3, .mosi=GPIO_NUM_18, .miso=GPIO_NUM_5, .sclk=GPIO_NUM_19}

//SPI Devices
#define HAL_ESP32_SPI_DEVICES {.name=HAL_INS_MPU9250_NAME, .bus=0, .device=0, .cs=GPIO_NUM_17, .mode=0, .lspeed=4*MHZ, .hspeed=4*MHZ}, \
{.name=HAL_INS_BMI160_NAME, .bus=0, .device=1, .cs=GPIO_NUM_5, .mode=0, .lspeed=4*MHZ, .hspeed=4*MHZ}

#define HAL_ESP32_SPI_DEVICES {.name=HAL_INS_MPU9250_NAME, .bus=0, .device=1, .cs=GPIO_NUM_16, .mode=0, .lspeed=4*MHZ, .hspeed=4*MHZ},\
{.name=HAL_INS_MPU6500_NAME, .bus=0, .device=0, .cs=GPIO_NUM_23, .mode=0, .lspeed=4*MHZ, .hspeed=4*MHZ}
//RCIN
#define HAL_ESP32_RCIN GPIO_NUM_13
#define HAL_ESP32_RCIN GPIO_NUM_22

//RCOUT
#define HAL_ESP32_RCOUT {GPIO_NUM_32, GPIO_NUM_33, GPIO_NUM_25, GPIO_NUM_26, GPIO_NUM_27}
#define HAL_ESP32_RCOUT {GPIO_NUM_14, GPIO_NUM_15, GPIO_NUM_17, GPIO_NUM_21}

//BAROMETER
#define HAL_BARO_ALLOW_INIT_NO_BARO 1
#define AP_BARO_BMP280_ENABLED 1
#define HAL_BARO_PROBE_LIST PROBE_BARO_I2C(BMP280,0,0x76)
#define HAL_BARO_PROBE_LIST PROBE_BARO_I2C(BMP280,0,0x76); \
PROBE_BARO_I2C(BMP280,0,0x76);

//COMPASS
#define HAL_COMPASS_MAX_SENSORS 3
#define HAL_MAG_PROBE_LIST PROBE_MAG_I2C(QMC5883L, 0, 0x0D, false, ROTATION_YAW_270); \
PROBE_MAG_IMU(AK8963, mpu9250, 0, ROTATION_YAW_90)
#define HAL_MAG_PROBE_LIST PROBE_MAG_I2C(QMC5883L, 0, 0x0D, false, ROTATION_YAW_90);\
PROBE_MAG_IMU(AK8963, mpu9250, 0, ROTATION_YAW_90);
/*
#define HAL_MAG_PROBE_LIST PROBE_MAG_I2C(QMC5883L, 0, 0x0D, false, ROTATION_NONE); \
PROBE_MAG_IMU(AK8963, mpu9250, 0, ROTATION_NONE)
Expand All @@ -123,8 +124,8 @@
//UARTs
#define HAL_ESP32_UART_DEVICES \
{.port=UART_NUM_0, .rx=GPIO_NUM_3 , .tx=GPIO_NUM_1 },\
{.port=UART_NUM_1, .rx=GPIO_NUM_4, .tx=GPIO_NUM_16}, \
{.port=UART_NUM_2, .rx=GPIO_NUM_15, .tx=GPIO_NUM_12}
{.port=UART_NUM_1, .rx=GPIO_NUM_35, .tx=GPIO_NUM_12}, \
{.port=UART_NUM_2, .rx=GPIO_NUM_34, .tx=GPIO_NUM_4}

//ADC
#define HAL_DISABLE_ADC_DRIVER 1
Expand All @@ -138,11 +139,11 @@
*/

//LED
#define DEFAULT_NTF_LED_TYPES Notify_LED_None
#define DEFAULT_NTF_LED_TYPES Notify_LED_Board
#define HAL_GPIO_LED_ON 1
#define HAL_GPIO_LED_OFF 0
//#define HAL_GPIO_A_LED_PIN 2
//#define HAL_GPIO_B_LED_PIN 27
#define HAL_GPIO_A_LED_PIN 0
#define HAL_GPIO_B_LED_PIN 2

//Buzzer Pin
//#define BUZZER_ENABLE_DEFAULT 1 //Enabling internal buzzer, see AP_Notify.cpp
Expand All @@ -157,21 +158,23 @@
// as mmc uses specific pins but is quicker,
// and spi is more flexible pinouts.... dont forget vspi/hspi should be selected to NOT conflict with HAL_ESP32_SPI_BUSES

//#define HAL_ESP32_SDCARD //after enabled, uncomment one of below
#define HAL_ESP32_SDCARD //after enabled, uncomment one of below
//#define HAL_ESP32_SDMMC
//#define HAL_ESP32_SDSPI {.host=VSPI_HOST, .dma_ch=2, .mosi=GPIO_NUM_2, .miso=GPIO_NUM_15, .sclk=GPIO_NUM_26, .cs=GPIO_NUM_21}
#define HAL_ESP32_SDSPI {.host=HSPI_HOST, .dma_ch=3, .mosi=GPIO_NUM_25, .miso=GPIO_NUM_27, .sclk=GPIO_NUM_26, .cs=GPIO_NUM_33}

//#define HAL_LOGGING_FILESYSTEM_ENABLED 0
#define HAVE_FILESYSTEM_SUPPORT 0
#define HAL_LOGGING_DATAFLASH_ENABLED 0
#define HAL_LOGGING_MAVLINK_ENABLED 0
#define HAL_LOGGING_FILESYSTEM_ENABLED 1
#define HAVE_FILESYSTEM_SUPPORT 1
#define HAL_LOGGING_DATAFLASH_ENABLED 1
#define HAL_LOGGING_MAVLINK_ENABLED 1

#define HAL_BOARD_LOG_DIRECTORY "/SDCARD/APM/LOGS"
#define HAL_BOARD_STORAGE_DIRECTORY "/SDCARD/APM/STORAGE"
#define HAL_BOARD_LOG_DIRECTORY "/SDCARD/APM/LOGS"
#define HAL_BOARD_TERRAIN_DIRECTORY "/SDCARD/APM/TERRAIN"

#define HAL_LOGGING_BACKENDS_DEFAULT 0
#define HAL_LOGGING_BACKENDS_DEFAULT 1
//#define AP_NOTIFY_TONEALARM_ENABLED 1 //this definition is for activating ToneAlarm
//#define HAL_PWM_BUZZER_PIN 14 //pin of where your ToneAlarm buzzer is
//#define HAL_PWM_BUZZER_PIN 14 //pin of where your ToneAlarm buzzer is
//#define AP_SBUSOUTPUT_ENABLED TRUE
//#define SBUS_OUT_PIN GPIO_NUM_21

12 changes: 12 additions & 0 deletions libraries/AP_InertialSensor/AP_InertialSensor_Invensense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ AP_InertialSensor_Backend *AP_InertialSensor_Invensense::probe(AP_InertialSensor
}
if (sensor->_mpu_type == Invensense_MPU9250) {
sensor->_id = HAL_INS_MPU9250_SPI;
printf("MPU9250 Detected!");
} else if (sensor->_mpu_type == Invensense_MPU6500) {
sensor->_id = HAL_INS_MPU6500;
} else {
Expand All @@ -164,6 +165,12 @@ bool AP_InertialSensor_Invensense::_init()
#endif

bool success = _hardware_init();
if (success == TRUE) {
printf("FAIL!");
}
else {
printf("SUCCESS!");
}

return success;
}
Expand Down Expand Up @@ -959,6 +966,8 @@ void AP_InertialSensor_Invensense::_set_filter_register(void)
bool AP_InertialSensor_Invensense::_check_whoami(void)
{
uint8_t whoami = _register_read(MPUREG_WHOAMI);
printf("%d", whoami);
printf("\n");
switch (whoami) {
case MPU_WHOAMI_6000:
_mpu_type = Invensense_MPU6000;
Expand Down Expand Up @@ -995,6 +1004,7 @@ bool AP_InertialSensor_Invensense::_check_whoami(void)

bool AP_InertialSensor_Invensense::_hardware_init(void)
{
printf("begin HW initialization!");
WITH_SEMAPHORE(_dev->get_semaphore());

// setup for register checking. We check much less often on I2C
Expand All @@ -1005,6 +1015,7 @@ bool AP_InertialSensor_Invensense::_hardware_init(void)
_dev->set_speed(AP_HAL::Device::SPEED_LOW);

if (!_check_whoami()) {
printf("WHOAMI FAIL!\n");
return false;
}

Expand Down Expand Up @@ -1069,6 +1080,7 @@ bool AP_InertialSensor_Invensense::_hardware_init(void)

if (tries == 5) {
DEV_PRINTF("Failed to boot Invensense 5 times\n");
printf("Failed to boot Invensense 5 times\n");
return false;
}

Expand Down
49 changes: 33 additions & 16 deletions libraries/AP_Notify/AP_BoardLED2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@
// show all status on only 2 leds

#if defined(HAL_GPIO_A_LED_PIN) && defined(HAL_GPIO_B_LED_PIN)
#if CONFIG_HAL_BOARD == HAL_BOARD_ESP32
#if HAL_GPIO_A_LED_PIN == 0

#define HAL_GPIO_LED_A_ON 0
#define HAL_GPIO_LED_A_OFF 1

#else

#define HAL_GPIO_LED_A_ON 1
#define HAL_GPIO_LED_A_OFF 0
#endif //HAL_GPIO_A_LED_PIN

#else
#define HAL_GPIO_LED_A_ON 1
#define HAL_GPIO_LED_A_OFF 0

#endif //CONFIG_HAL_BOARD

static_assert((HAL_GPIO_A_LED_PIN != HAL_GPIO_B_LED_PIN), "Duplicate LED assignments detected");

Expand All @@ -32,7 +49,7 @@ bool AP_BoardLED2::init(void)
hal.gpio->pinMode(HAL_GPIO_B_LED_PIN, HAL_GPIO_OUTPUT);

// turn all lights off
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_OFF);
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_A_OFF);
hal.gpio->write(HAL_GPIO_B_LED_PIN, HAL_GPIO_LED_OFF);

_sat_cnt=0;
Expand Down Expand Up @@ -74,11 +91,11 @@ void AP_BoardLED2::update(void)
switch(save_trim_counter) {
case 0:
hal.gpio->write(HAL_GPIO_B_LED_PIN, HAL_GPIO_LED_OFF);
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_ON);
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_A_ON);
break;

case 1:
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_OFF);
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_A_OFF);
hal.gpio->write(HAL_GPIO_B_LED_PIN, HAL_GPIO_LED_ON);
break;

Expand All @@ -94,12 +111,12 @@ void AP_BoardLED2::update(void)
// compass calibration or IMU temperature calibration
switch(save_trim_counter) {
case 0:
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_ON); // short blinks by both LEDs
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_A_ON); // short blinks by both LEDs
hal.gpio->write(HAL_GPIO_B_LED_PIN, HAL_GPIO_LED_ON);
break;
case 1:
case 2:
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_OFF);
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_A_OFF);
hal.gpio->write(HAL_GPIO_B_LED_PIN, HAL_GPIO_LED_OFF);
break;
case 3:
Expand All @@ -120,15 +137,15 @@ void AP_BoardLED2::update(void)
if(AP_Notify::events.autotune_complete){
switch(save_trim_counter) {
case 0:
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_ON); // short darkening
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_A_ON); // short darkening
break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_OFF);
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_A_OFF);
break;
case 7:
break;
Expand All @@ -143,20 +160,20 @@ void AP_BoardLED2::update(void)
if(AP_Notify::events.autotune_failed){
switch(save_trim_counter) {
case 0:
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_ON); // short double darkening
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_A_ON); // short double darkening
break;
case 1:
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_OFF);
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_A_OFF);
break;
case 2:
case 3:
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_ON);
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_A_ON);
break;
case 4:
case 5:
case 6:
case 7:
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_OFF);
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_A_OFF);
break;
default:
// reset counter to restart the sequence
Expand All @@ -179,7 +196,7 @@ void AP_BoardLED2::update(void)
}
} else {
// ARM led solid
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_ON);
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_A_ON);
}
}else{
if ((counter2 & 0x2) == 0) {
Expand All @@ -193,7 +210,7 @@ void AP_BoardLED2::update(void)
case 1:
case 2:
case 3:
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_ON);
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_A_ON);
break;
case 4:
case 5:
Expand All @@ -211,7 +228,7 @@ void AP_BoardLED2::update(void)
switch(arm_counter) {
case 0:
case 1:
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_ON);
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_A_ON);
break;

case 2:
Expand All @@ -221,13 +238,13 @@ void AP_BoardLED2::update(void)

case 3:
case 4:
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_ON);
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_A_ON);
break;

case 5:
case 6:
case 7: // add one tick to do period be a multiple of the second
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_OFF);
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_A_OFF);
break;

default:
Expand Down

0 comments on commit 53272a9

Please sign in to comment.