Skip to content

Commit

Permalink
don't call led_init() from mcu_init anymore, instead call the indiivd…
Browse files Browse the repository at this point in the history
…ual LED_INIT(x) wherever they are used

This way we can actually define all the leds in the board files, but only initialized the actually used ones.
Otherwise we would render the ADC_1-3 useless by automatically initializing
the leds 6,7,8 on lisa/m 2.0 (which are not populated by default anyway).
  • Loading branch information
flixr committed May 15, 2012
1 parent ee72738 commit 46f7182
Show file tree
Hide file tree
Showing 31 changed files with 154 additions and 12 deletions.
4 changes: 4 additions & 0 deletions sw/airborne/arch/lpc21/ADS8344.c
Expand Up @@ -103,6 +103,10 @@ void ADS8344_init( void ) {
/* configure SS pin */
SetBit( ADS8344_SS_IODIR, ADS8344_SS_PIN); /* pin is output */
ADS8344Unselect(); /* pin low */

// FIXME, no hardcoded led numbers
LED_INIT(2);
LED_OFF(2);
}

static inline void read_values( void ) {
Expand Down
5 changes: 5 additions & 0 deletions sw/airborne/arch/lpc21/mcu_periph/sys_time_arch.c
Expand Up @@ -120,6 +120,11 @@ void sys_time_arch_init( void ) {
_VIC_CNTL(TIMER0_VIC_SLOT) = VIC_ENABLE | VIC_TIMER0;
/* address of the ISR */
_VIC_ADDR(TIMER0_VIC_SLOT) = (uint32_t)TIMER0_ISR;

//FIXME, no hardcoded led number
#ifdef TRIGGER_EXT
LED_INIT(3);
#endif
}


Expand Down
8 changes: 7 additions & 1 deletion sw/airborne/arch/lpc21/uart_tunnel.c
Expand Up @@ -15,8 +15,14 @@ int main (int argc, char** argv) {
int tx=0, rx=0;
int tx_shadow=1, rx_shadow=1;
mcu_init();
led_init();

// FIXME, no hardcoded led numbers
LED_INIT(1);
LED_ON(1);
LED_INIT(2);
LED_OFF(2);
LED_INIT(3);
LED_OFF(3);

/* TXD0 and TXD1 output */
SetBit(IO0DIR, TXD0_PIN);
Expand Down
10 changes: 9 additions & 1 deletion sw/airborne/arch/lpc21/usb_tunnel.c
Expand Up @@ -46,7 +46,15 @@ int main( void ) {

mcu_init();
sys_time_init();
led_init();

// FIXME, no hardcoded led numbers
LED_INIT(1);
LED_ON(1);
LED_INIT(2);
LED_OFF(2);
LED_INIT(3);
LED_OFF(3);

VCOM_allow_linecoding(1);

#ifdef USE_USB_SERIAL
Expand Down
1 change: 1 addition & 0 deletions sw/airborne/boards/booz/baro_board.c
Expand Up @@ -49,6 +49,7 @@ void baro_init( void ) {
baro_board.value_filtered = 0;
baro_board.data_available = FALSE;
#ifdef ROTORCRAFT_BARO_LED
LED_INIT(ROTORCRAFT_BARO_LED);
LED_OFF(ROTORCRAFT_BARO_LED);
#endif
}
Expand Down
1 change: 1 addition & 0 deletions sw/airborne/boards/navgo/baro_board.c
Expand Up @@ -43,6 +43,7 @@ void baro_init( void ) {
baro.absolute = 0;
baro.differential = 0; /* not handled on this board */
#ifdef ROTORCRAFT_BARO_LED
LED_INIT(ROTORCRAFT_BARO_LED);
LED_OFF(ROTORCRAFT_BARO_LED);
#endif
startup_cnt = STARTUP_COUNTER;
Expand Down
9 changes: 9 additions & 0 deletions sw/airborne/firmwares/fixedwing/main_ap.c
Expand Up @@ -169,6 +169,15 @@ void init_ap( void ) {
mcu_init();
#endif /* SINGLE_MCU */

#ifdef POWER_SWITCH_LED
LED_INIT(POWER_SWITCH_LED);
LED_OFF(POWER_SWITCH_LED);
#endif
#ifdef AHRS_CPU_LED
LED_INIT(AHRS_CPU_LED);
LED_OFF(AHRS_CPU_LED);
#endif

/************* Sensors initialization ***************/
#if USE_GPS
gps_init();
Expand Down
14 changes: 13 additions & 1 deletion sw/airborne/firmwares/logger/main_logger.c
Expand Up @@ -572,7 +572,19 @@ int main(void)
static inline void main_init( void ) {
mcu_init();
sys_time_init();
led_init();

LED_INIT(LED_RED);
LED_OFF(LED_RED);
LED_INIT(LED_GREEN);
LED_OFF(LED_GREEN);
LED_INIT(LED_YELLOW);
LED_OFF(LED_YELLOW);

//FIXME, no hardcoded led numbers
LED_INIT(1);
LED_OFF(1);
LED_INIT(2);
LED_OFF(2);

#ifdef USE_MAX11040
max11040_init_ssp();
Expand Down
1 change: 1 addition & 0 deletions sw/airborne/firmwares/rotorcraft/autopilot.c
Expand Up @@ -78,6 +78,7 @@ void autopilot_init(void) {
autopilot_rc = TRUE;
autopilot_power_switch = FALSE;
#ifdef POWER_SWITCH_LED
LED_INIT(POWER_SWITCH_LED);
LED_ON(POWER_SWITCH_LED); // POWER OFF
#endif
autopilot_arming_init();
Expand Down
5 changes: 5 additions & 0 deletions sw/airborne/lisa/lisa_overo_link.c
Expand Up @@ -10,6 +10,11 @@ void overo_link_init(void) {
overo_link.crc_error = FALSE;
overo_link.timeout = FALSE;
overo_link_arch_init();

LED_INIT(OVERO_LINK_LED_OK);
LED_INIT(OVERO_LINK_LED_KO);
LED_OFF(OVERO_LINK_LED_OK);
LED_OFF(OVERO_LINK_LED_KO);
}


Expand Down
2 changes: 2 additions & 0 deletions sw/airborne/lisa/test_spi_slave.c
Expand Up @@ -53,6 +53,8 @@ int main(void) {

static inline void main_init( void ) {
mcu_init();
LED_INIT(3);
LED_OFF(3);
sys_time_register_timer((1./PERIODIC_FREQUENCY), NULL);
main_spi_slave_init();
}
Expand Down
4 changes: 4 additions & 0 deletions sw/airborne/lisa/test_uart_lisam.c
Expand Up @@ -52,6 +52,10 @@ int main(void) {
static inline void main_init( void ) {
mcu_init();
sys_time_register_timer((1./PERIODIC_FREQUENCY), NULL);
LED_INIT(1);
LED_INIT(2);
LED_OFF(1);
LED_OFF(2);
}

static inline void main_periodic( void ) {
Expand Down
3 changes: 3 additions & 0 deletions sw/airborne/lisa/tunnel_hw.c
Expand Up @@ -55,6 +55,9 @@ int main(void) {
mcu_init();
sys_time_register_timer((1./PERIODIC_FREQUENCY), NULL);

LED_INIT(2);
LED_OFF(2);

/* init RCC */
RCC_APB2PeriphClockCmd(A_PERIPH , ENABLE);
// RCC_APB2PeriphClockCmd(B_PERIPH , ENABLE);
Expand Down
3 changes: 0 additions & 3 deletions sw/airborne/mcu.c
Expand Up @@ -60,9 +60,6 @@ void mcu_init(void) {

#ifdef PERIPHERALS_AUTO_INIT
sys_time_init();
#ifdef USE_LED
led_init();
#endif
/* for now this means using spektrum */
#if defined RADIO_CONTROL & defined RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT & defined RADIO_CONTROL_BIND_IMPL_FUNC
RADIO_CONTROL_BIND_IMPL_FUNC();
Expand Down
6 changes: 6 additions & 0 deletions sw/airborne/mcu_periph/sys_time.c
Expand Up @@ -29,6 +29,7 @@

#include "mcu_periph/sys_time.h"
#include "mcu.h"
#include "led.h"

struct sys_time sys_time;

Expand Down Expand Up @@ -69,6 +70,11 @@ void sys_time_update_timer(tid_t id, float duration) {
void sys_time_init( void ) {
sys_time_arch_init();

#ifdef SYS_TIME_LED
LED_INIT(SYS_TIME_LED);
LED_OFF(SYS_TIME_LED);
#endif

sys_time.nb_sec = 0;
sys_time.nb_sec_rem = 0;
sys_time.nb_tick = 0;
Expand Down
8 changes: 6 additions & 2 deletions sw/airborne/modules/benchmark/i2c_abuse_test.c
Expand Up @@ -33,8 +33,12 @@ volatile uint8_t i2c_abuse_test_counter = 0;
volatile uint32_t i2c_abuse_test_bitrate = 1000;

void init_i2c_abuse_test(void) {
//LED_INIT(DEMO_MODULE_LED);
//LED_OFF(DEMO_MODULE_LED);
LED_INIT(4);
LED_OFF(4);
LED_INIT(5);
LED_OFF(5);
LED_INIT(I2C_ABUSE_LED);
LED_OFF(I2C_ABUSE_LED);

i2c_test1.status = I2CTransSuccess;
i2c_test1.slave_addr = 0x3C;
Expand Down
2 changes: 2 additions & 0 deletions sw/airborne/modules/cam_control/booz_cam.c
Expand Up @@ -73,6 +73,8 @@ int16_t booz_cam_pan;
#endif

void booz_cam_init(void) {
LED_INIT(CAM_SWITCH_LED);
LED_ON(CAM_SWITCH_LED);
booz_cam_SetCamMode(BOOZ_CAM_DEFAULT_MODE);
#ifdef BOOZ_CAM_USE_TILT
booz_cam_tilt_pwm = BOOZ_CAM_TILT_NEUTRAL;
Expand Down
4 changes: 4 additions & 0 deletions sw/airborne/modules/cam_control/cam.c
Expand Up @@ -101,6 +101,10 @@ void cam_waypoint_target(void);
void cam_ac_target(void);

void cam_init( void ) {
#ifdef VIDEO_TX_SWITCH
LED_INIT(VIDEO_TX_SWITCH);
#endif

cam_mode = CAM_MODE0;
}

Expand Down
11 changes: 11 additions & 0 deletions sw/airborne/modules/digital_cam/led_cam_ctrl.h
Expand Up @@ -54,6 +54,17 @@ extern uint8_t dc_timer;

static inline void led_cam_ctrl_init(void)
{
LED_INIT(DC_SHUTTER_LED);
#ifdef DC_ZOOM_IN_LED
LED_INIT(DC_ZOOM_IN_LED);
#endif
#ifdef DC_ZOOM_OUT_LED
LED_INIT(DC_ZOOM_OUT_LED);
#endif
#ifdef DC_POWER_LED
LED_INIT(DC_POWER_LED);
#endif

// Call common DC init
dc_init();

Expand Down
2 changes: 2 additions & 0 deletions sw/airborne/modules/gsm/gsm.c
Expand Up @@ -152,6 +152,8 @@ static uint8_t gcs_index_max;

/*****************************************************************************/
void gsm_init(void) {
LED_INIT(GSM_ONOFF_LED);

if (gsm_status == STATUS_NONE) { /* First call */
LED_ON(GSM_ONOFF_LED);
gsm_status = STATUS_POWERON;
Expand Down
3 changes: 3 additions & 0 deletions sw/airborne/modules/ins/ins_chimu_spi.c
Expand Up @@ -38,6 +38,9 @@ volatile uint8_t new_ins_attitude;

void ins_init( void )
{
// FIXME, don't use hardcode led number here
LED_INIT(3);

// uint8_t ping[7] = {CHIMU_STX, CHIMU_STX, 0x01, CHIMU_BROADCAST, MSG00_PING, 0x00, 0xE6 };
uint8_t rate[12] = {CHIMU_STX, CHIMU_STX, 0x06, CHIMU_BROADCAST, MSG10_UARTSETTINGS, 0x05, 0xff, 0x79, 0x00, 0x00, 0x01, 0x76 }; // 50Hz attitude only + SPI
uint8_t quaternions[7] = {CHIMU_STX, CHIMU_STX, 0x01, CHIMU_BROADCAST, MSG09_ESTIMATOR, 0x01, 0x39 }; // 25Hz attitude only + SPI
Expand Down
3 changes: 3 additions & 0 deletions sw/airborne/modules/ins/ins_chimu_uart.c
Expand Up @@ -37,6 +37,9 @@ volatile uint8_t new_ins_attitude;

void ins_init( void )
{
// FIXME, don't use hardcode led number here
LED_INIT(3);

uint8_t ping[7] = {CHIMU_STX, CHIMU_STX, 0x01, CHIMU_BROADCAST, MSG00_PING, 0x00, 0xE6 };
uint8_t rate[12] = {CHIMU_STX, CHIMU_STX, 0x06, CHIMU_BROADCAST, MSG10_UARTSETTINGS, 0x05, 0xff, 0x79, 0x00, 0x00, 0x01, 0x76 }; // 50Hz attitude only + SPI
uint8_t quaternions[7] = {CHIMU_STX, CHIMU_STX, 0x01, CHIMU_BROADCAST, MSG09_ESTIMATOR, 0x01, 0x39 }; // 25Hz attitude only + SPI
Expand Down
8 changes: 8 additions & 0 deletions sw/airborne/modules/ins/ins_xsens.c
Expand Up @@ -226,6 +226,14 @@ volatile int xsens_configured = 0;

void ins_init( void ) {

// FIXME, don't use hardcode led number here
LED_INIT(3);

#ifdef GPS_LED
LED_INIT(GPS_LED);
LED_OFF(GPS_LED);
#endif

xsens_status = UNINIT;
xsens_configured = 20;

Expand Down
7 changes: 6 additions & 1 deletion sw/airborne/modules/meteo/humid_sht.c
Expand Up @@ -237,8 +237,13 @@ uint8_t humid_sht_reset( void )

void humid_sht_init( void )
{
/* Configure DAT/SCL pin as GPIO */
// FIXME, should not use hardcoded led number
LED_INIT(2);
LED_OFF(2);

// FIXME, should not contain arch dependent code here

/* Configure DAT/SCL pin as GPIO */
#if (DAT_PIN<16)
PINSEL0 &= ~(_BV(DAT_PIN*2)|_BV(DAT_PIN*2+1));
#else
Expand Down
5 changes: 4 additions & 1 deletion sw/airborne/sd_card/main.c
Expand Up @@ -36,7 +36,10 @@ int main( void ) {
static inline void main_init( void ) {
mcu_init();
sys_time_register_timer((1./PERIODIC_FREQUENCY), NULL);
led_init();

LED_INIT(1);
LED_OFF(1);

Uart0Init();

spi_init();
Expand Down
5 changes: 5 additions & 0 deletions sw/airborne/subsystems/ahrs/ahrs_aligner.c
Expand Up @@ -46,6 +46,11 @@ void ahrs_aligner_init(void) {
samples_idx = 0;
ahrs_aligner.noise = 0;
ahrs_aligner.low_noise_cnt = 0;

#ifdef AHRS_ALIGNER_LED
LED_INIT(AHRS_ALIGNER_LED);
LED_OFF(AHRS_ALIGNER_LED);
#endif
}

#ifndef LOW_NOISE_THRESHOLD
Expand Down
1 change: 1 addition & 0 deletions sw/airborne/subsystems/gps.c
Expand Up @@ -38,6 +38,7 @@ void gps_init(void) {
gps.fix = GPS_FIX_NONE;
gps.cacc = 0;
#ifdef GPS_LED
LED_INIT(GPS_LED);
LED_OFF(GPS_LED);
#endif
#ifdef GPS_TYPE_H
Expand Down
5 changes: 5 additions & 0 deletions sw/airborne/subsystems/radio_control.h
Expand Up @@ -71,6 +71,11 @@ static inline void radio_control_init ( void ) {
radio_control.frame_rate = 0;
radio_control.frame_cpt = 0;
radio_control_impl_init();

#if defined RADIO_CONTROL_LED
LED_INIT(RADIO_CONTROL_LED);
LED_OFF(RADIO_CONTROL_LED);
#endif
}

/************* PERIODIC ******************************************************/
Expand Down
14 changes: 14 additions & 0 deletions sw/airborne/test/mcu_periph/test_sys_time.c
Expand Up @@ -11,6 +11,20 @@ static inline void main_event( void );
int main(void) {

mcu_init();

#ifdef LED_GREEN
LED_INIT(LED_GREEN);
LED_OFF(LED_GREEN);
#endif
#ifdef LED_BLUE
LED_INIT(LED_BLUE);
LED_OFF(LED_BLUE);
#endif
#ifdef LED_RED
LED_INIT(LED_RED);
LED_OFF(LED_RED);
#endif

unsigned int tmr_02 = sys_time_register_timer(0.2, NULL);
unsigned int tmr_03 = sys_time_register_timer(0.3, NULL);
sys_time_register_timer(0.5, main_periodic_05);
Expand Down
7 changes: 6 additions & 1 deletion sw/airborne/test/subsystems/test_imu.c
Expand Up @@ -61,6 +61,11 @@ static inline void main_init( void ) {

mcu_init();

#ifdef BOARD_LISA_L
LED_INIT(3);
LED_OFF(3);
#endif

sys_time_register_timer((1./PERIODIC_FREQUENCY), NULL);

imu_init();
Expand All @@ -71,7 +76,7 @@ static inline void main_init( void ) {
static inline void led_toggle ( void ) {

#ifdef BOARD_LISA_L
LED_TOGGLE(3);
LED_TOGGLE(3);
#endif
}

Expand Down
5 changes: 4 additions & 1 deletion sw/airborne/test/test_adcs.c
Expand Up @@ -21,7 +21,10 @@ static struct adc_buf buf_adc[NB_ADC];
int main (int argc, char** argv) {
mcu_init();
sys_time_register_timer((1./PERIODIC_FREQUENCY), NULL);
led_init();

LED_INIT(1);
LED_OFF(1);

adc_init();

adc_buf_channel(ADC_0, &buf_adc[0], ADC_NB_SAMPLES);
Expand Down

2 comments on commit 46f7182

@gautierhattenberger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like to change the automatic initialization of the leds for only one board (up to now).
I think it's lisa_xx.h that should not define LED_X_BANK if they don't want it by default.
Also this LED_X_BANK name is not a good choice anymore to test if led is defined. It should be something like USE_LED_X (defined only for default led and automatically initialized). Defining it in the airframe file could activate the non-standard ones.

@flixr
Copy link
Member Author

@flixr flixr commented on 46f7182 May 18, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this is just a temporary hack. We have that problem on some other boards/leds/gpios as well...
@esden wanted to write a new gpio interface anyway. The led interface would use that and should then only be used for the onboard leds, everything else should not abuse led, but use the gpio directly then. There we need a better way to define which gpios are actually used, and still make it possible to define the which onboard led is on which pin.

If you want you can revert this commit and change the LED_x_BANK to USE_LED_X instead... that would be indeed nicer until we have a proper gpio interface/api.

Please sign in to comment.