Exemple #1
0
int main(void)
{	
	char str_buf[30];	
	int32_t value =43552;
	LED_Init();
	ILI9341_Init();
	Usart1_Init(9600);
	Myprintf_Init(0x00,myputc);

	ILI9341_Puts(0,0,"LCD string test",&MY_Font_11x18,ILI9341_COLOR_WHITE,ILI9341_COLOR_BLUE);
	while(1) 
	{	
		//my_printf("It's usart1 test!\n");
		my_sprintf(str_buf,"%d\n",value);
		my_printf(str_buf);		
		LED_GREEN_ON();
		LED_RED_OFF();		
		delay(800000);
		LED_GREEN_OFF();
		LED_RED_ON();
		delay(800000);
	}

	return 0;
}
Exemple #2
0
void vBlinkerRequest(uint8_t cmd)
{
    switch (cmd & CMD_MASK)
    {
        case CMD_LED_ON:
            switch (cmd & LED_MASK)
            {
                case LED_RED:
                    LED_RED_ON();
                    break;
                case LED_GREEN:
                    LED_GREEN_ON();
                    break;
                case LED_BLUE:
                    LED_BLUE_ON();
                    break;
                case LED_ALL:
                    LEDS_ON();
                    break;
            }
            break;

        case CMD_LED_OFF:
            switch (cmd & LED_MASK)
            {
                case LED_RED:
                    LED_RED_OFF();
                    break;
                case LED_GREEN:
                    LED_GREEN_OFF();
                    break;
                case LED_BLUE:
                    LED_BLUE_OFF();
                    break;
                case LED_ALL:
                    LEDS_OFF();
                    break;
            }
            break;
        case CMD_LED_TOGGLE:
            switch (cmd & LED_MASK)
            {
                case LED_RED:
                    LED_RED_TOGGLE();
                    break;
                case LED_GREEN:
                    LED_GREEN_TOGGLE();
                    break;
                case LED_BLUE:
                    LED_BLUE_TOGGLE();
                    break;
                case LED_ALL:
                    LED_RED_TOGGLE();
                    LED_GREEN_TOGGLE();
                    LED_BLUE_TOGGLE();
                    break;
            }
            break;
    }
}
Exemple #3
0
/** Toggles LED
 * @param n iIndex of the LED to toggle. Red LED as index 0, green one 1 and blue one 2.
 */
void toggle_led( uint16_t n )
{
	led_state ^= (1 << n);

	if(led_state & 0x1) LED_RED_ON(); else LED_RED_OFF();
	if(led_state & 0x2) LED_GREEN_ON(); else LED_GREEN_OFF();
	if(led_state & 0x4) LED_BLUE_ON(); else LED_BLUE_OFF();
}
Exemple #4
0
static uint16_t beacon_sent(void) {
    beacon_eop_time = timerB_time();
    LED_RED_OFF();
    beacon_msg.seq++;

    cc1101_gdo0_register_callback(slot_data);
    LED_GREEN_ON();
    return 0;
}
Exemple #5
0
int main(void) {
    halInit();
    chSysInit();

    chThdSleepMilliseconds(1000);

    hw_init_gpio();
    LED_RED_OFF();
    LED_GREEN_OFF();

    conf_general_init();
    ledpwm_init();

    mc_configuration mcconf;
    conf_general_read_mc_configuration(&mcconf);
    mc_interface_init(&mcconf);

    commands_init();
    comm_usb_init();

    app_configuration appconf;
    conf_general_read_app_configuration(&appconf);
    app_init(&appconf);

    timeout_init();
    timeout_configure(appconf.timeout_msec, appconf.timeout_brake_current);

#if CAN_ENABLE
    comm_can_init();
#endif

#if WS2811_ENABLE
    ws2811_init();
    led_external_init();
#endif

#if ENCODER_ENABLE
    encoder_init();
#endif

#if SERVO_OUT_ENABLE
#if SERVO_OUT_SIMPLE
    servo_simple_init();
#else
    servo_init();
#endif
#endif

    // Threads
    chThdCreateStatic(periodic_thread_wa, sizeof(periodic_thread_wa), NORMALPRIO, periodic_thread, NULL);
    chThdCreateStatic(sample_send_thread_wa, sizeof(sample_send_thread_wa), NORMALPRIO - 1, sample_send_thread, NULL);
    chThdCreateStatic(timer_thread_wa, sizeof(timer_thread_wa), NORMALPRIO, timer_thread, NULL);

    for(;;) {
        chThdSleepMilliseconds(5000);
    }
}
Exemple #6
0
void main(void) {
    //leds:
    LED_INIT();

    //init clock source XOSC:
    clocksource_init();

    //init uart
    uart_init();

    //init wdt timer
    wdt_init();

    apa102_init();

    //init storage
    storage_init();

    //enable timeout routines
    timeout_init();

    //apa102_init();

    //init frsky core
    frsky_init();

    //init adc
    adc_init();

    //init output
    #if SBUS_ENABLED
    sbus_init();
    #else
    ppm_init();
    #endif

    //init failsafe
    failsafe_init();

    debug("main: init done\n");

    //run main
    //frsky_frame_sniffer();
    frsky_main();

    LED_RED_ON();
    while (1) {
        LED_RED_ON();
        delay_ms(200);
        LED_RED_OFF();
        delay_ms(200);
    }
}
Exemple #7
0
void do_Led_Flicker_Control(void)
{
    static U8 u8LedStatus = 0;
    if(u8LedStatus != 0)
    {
      LED_RED_ON();
    }
    else
    {
      LED_RED_OFF();
    }
    u8LedStatus = ~u8LedStatus;
  }
void Led_Config(void)
{
    GPIO_InitTypeDef gpio;
    
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
	
	gpio.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 ;
	gpio.GPIO_Mode = GPIO_Mode_OUT;
	gpio.GPIO_OType = GPIO_OType_PP;
	gpio.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_Init(GPIOC,&gpio);
    
    LED_GREEN_OFF();
    LED_RED_OFF();
}
Exemple #9
0
int main(void)
{	
	LED_Init();
	while(1) 
	{
		LED_GREEN_ON();
		LED_RED_ON();		
		delay(800000);
		LED_GREEN_OFF();
		LED_RED_OFF();
		delay(800000);
	}

	return 0;
}
Exemple #10
0
void Led_Configuration(void)
{
	GPIO_InitTypeDef gpio;

	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

	gpio.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
	gpio.GPIO_Mode = GPIO_Mode_OUT;
	gpio.GPIO_OType = GPIO_OType_PP;
	gpio.GPIO_Speed = GPIO_Speed_100MHz;
	gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_Init(GPIOA, &gpio);

	LED_GREEN_OFF();
	LED_RED_OFF();
}
Exemple #11
0
int main(void)
{

	float tempf;

	InitRCC();
	InitGPIO();
	InitADC();

	I2CInit();
	InitIT();
	Delay_Init(24);

	// reset pot value
	PotWrite(0x00);


    while(1) {
    	if (mode == MODE_CAL) {
    		LED_GREEN_ON();
    		LED_RED_OFF();
    		uint16_t av = ADC_GetConversionValue(AN_ADCx);
    		if (av > trig_level) {
    			trig_level = av;
    			tempf = GetADCVolt(trig_level)*VOLT_DIV; // get voltage from piezo
    			tempf = GetTargetK(tempf);		// get target amp coefficient
    			tempf = GetTargetR(tempf);		// get R2 for opamp feedback
    			tempf = GetPotR(tempf);			// get target resistance for pot as part of R2
    			PotWrite(GetWStep(tempf));		// write step to pot
    		}

    	} else {
    		// turn on red for working mode indication, turn green if mcu gets opamp output high
    		LED_RED_ON();
    		if (GPIO_ReadInputDataBit(OP_PORT, OP_PIN) == SET) {
    			LED_GREEN_ON();
    			delay_ms(500);
    		} else {
    			LED_GREEN_OFF();
    		}


    	}

    }

}
Exemple #12
0
/*
 * Call this function as fast as possible, with a deterministic rate.
 */
void ledpwm_update_pwm(void) {
    static int cnt = 0;
    cnt++;
    if (cnt == LEDPWM_CNT_TOP) {
        cnt = 0;
    }

    if (cnt >= led_values[0]) {
        LED_GREEN_OFF();
    } else {
        LED_GREEN_ON();
    }

    if (cnt >= led_values[1]) {
        LED_RED_OFF();
    } else {
        LED_RED_ON();
    }
}
Exemple #13
0
int main(void)
{	
	LED_Init();
	ILI9341_Init();

	ILI9341_Fill(ILI9341_COLOR_BLUE);
	ILI9341_Puts(0,0,"LCD string test",&MY_Font_11x18,ILI9341_COLOR_WHITE,ILI9341_COLOR_BLUE);
	while(1) 
	{	
		LED_GREEN_ON();
		LED_RED_OFF();		
		delay(800000);
		LED_GREEN_OFF();
		LED_RED_ON();
		delay(800000);
	}

	return 0;
}
Exemple #14
0
uint16_t packet_received(uint8_t packet[], uint16_t length,
			 uint16_t src_addr, int16_t rssi)
{
  spt_beacon_t *pkt=(spt_beacon_t *)packet;

#ifdef DEBUG
  LED_RED_ON();
#endif
  //notice_packet_received_mac();
  PRINTF("#> Packet from %x:\n", src_addr);
  if ( pkt->type == SPT_BEACON && my_seqnum != pkt->seqnum)
    {
      my_state = STATE_ACTIVE;
      cpt_last_beacon = 0;
      num_slot = 1;
      my_seqnum = pkt->seqnum;
      beacon_received = 1;
    }
#ifdef DEBUG
  LED_RED_OFF();
#endif

  return 0;
}
Exemple #15
0
int main(void) {
	volatile int16_t* samples;
	unsigned int i;
	DISABLE_GLOBAL_INT();
	/* stop watchdog timer */
	WDTCTL = WDTPW +WDTHOLD;
	/* SET CPU to 5MHz */
	/* max DCO
	   MCLK = DCOCLK
	   SMCLK = DCOCLK
	   ACLK = 8KHz
	*/
	DCOCTL = DCO0 + DCO1 + DCO2;
	BCSCTL1 = RSEL0 + RSEL1 + RSEL2 + XT2OFF;
	BCSCTL2 = 0x00;

	delay_us(10000);

	/* activate Active Mode */
	__bic_SR_register(LPM4_bits);

	/* set LEDs when loaded */
	P5SEL = 0x00;
	P5DIR = 0x70;
	LED_RED_ON();
	LED_GREEN_OFF();
	LED_BLUE_OFF();

	check_for_clock();
	init_usb_serial();
#ifdef USE_DMA
	init_dma(&g_sample_flag);
#endif

#ifdef TX
	init_adc(&g_sample_flag);
#else
	init_dac();
#endif
	init_rf(RF_CHANNEL, PAN_ID, NODE_ADDR, &g_sample_flag);

	debug_print("Successfully booted.\n");
	/* set LEDS to signalize finished initilizing */
	LED_RED_OFF();
	ENABLE_GLOBAL_INT();

#ifdef TX
	/* TX */
	while(1) {
		if(g_sample_flag == 1) {
			g_sample_flag = 0;
#ifdef USE_DMA
			/* get samples */
			samples = get_samples_dma();
#else
			/* get samples */
			samples = get_samples();
#endif
			/* send oder radio, 2*num_words */
			send_rf_data(RF_RX_ADDR, (uint8_t*) samples, NUM_SAMPLES*2);
		}
		/* reset WDT */
		WDTCTL = WDTPW + WDTCNTCL;

	}
#else
	/* RX */
	while(1) {
		if(g_sample_flag == 1) {
			g_sample_flag = 0;
			samples = get_samples_rf();
#if 0
			uint8_t err = 0;
			for(i = 0; i < NUM_SAMPLES; ++i) {
				//samples[i] = 4095-7*i;
				usb_printf("%d\n", samples[i]);
				//if( ((uint16_t) samples[i]) > 4095) {
				//	usb_printf("i=%u\n", i);
				//	++err;
				//}
			}
			usb_printf("#error: %u\n", err);
			usb_printf("\n\n");
#endif			
			set_dma_data(samples, NUM_SAMPLES);
		}
		/* reset WDT */
		WDTCTL = WDTPW + WDTCNTCL;
	}
#endif
	return 0;
}
/* Main function */
int main(void)
{
    int value_mg_x, value_mg_y, value_mg_z;

    /* setup all GPIOs */
    gpio_setup();

    /* initialise LIS3DSH */
    lis3dsh_init();

    /* infinite loop */
    while (1) {
        /* get X, Y, Z values */
        value_mg_x = ((lis3dsh_read_reg(ADD_REG_OUT_X_H) << 8) |
                      lis3dsh_read_reg(ADD_REG_OUT_X_L));
        value_mg_y = ((lis3dsh_read_reg(ADD_REG_OUT_Y_H) << 8) |
                      lis3dsh_read_reg(ADD_REG_OUT_Y_L));
        value_mg_z = ((lis3dsh_read_reg(ADD_REG_OUT_Z_H) << 8) |
                      lis3dsh_read_reg(ADD_REG_OUT_Z_L));

        /* transform X value from two's complement to 16-bit int */
        value_mg_x = two_compl_to_int16(value_mg_x);
        /* convert X absolute value to mg value */
        value_mg_x = value_mg_x * SENS_2G_RANGE_MG_PER_DIGIT;

        /* transform Y value from two's complement to 16-bit int */
        value_mg_y = two_compl_to_int16(value_mg_y);
        /* convert Y absolute value to mg value */
        value_mg_y = value_mg_y * SENS_2G_RANGE_MG_PER_DIGIT;

        /* transform Z value from two's complement to 16-bit int */
        value_mg_z = two_compl_to_int16(value_mg_z);
        /* convert Z absolute value to mg value */
        value_mg_z = value_mg_z * SENS_2G_RANGE_MG_PER_DIGIT;

        /* set X related LEDs according to specified threshold */
        if (value_mg_x >= LED_TH_MG) {
            LED_BLUE_OFF();
            LED_ORANGE_OFF();
            LED_GREEN_OFF();
            LED_RED_ON();
        } else if (value_mg_x <= -LED_TH_MG) {
            LED_BLUE_OFF();
            LED_ORANGE_OFF();
            LED_RED_OFF();
            LED_GREEN_ON();
        }

        /* set Y related LEDs according to specified threshold */
        if (value_mg_y >= LED_TH_MG) {
            LED_BLUE_OFF();
            LED_RED_OFF();
            LED_GREEN_OFF();
            LED_ORANGE_ON();
        } else if (value_mg_y <= -LED_TH_MG) {
            LED_RED_OFF();
            LED_GREEN_OFF();
            LED_ORANGE_OFF();
            LED_BLUE_ON();
        }

        /* set Z related LEDs according to specified threshold */
        if (value_mg_z >= LED_TH_MG) {
            LED_BLUE_ON();
            LED_ORANGE_ON();
            LED_RED_ON();
            LED_GREEN_ON();
        } else if (value_mg_z <= -LED_TH_MG) {
            LED_BLUE_OFF();
            LED_ORANGE_OFF();
            LED_RED_OFF();
            LED_GREEN_OFF();
        }
    }

    return 0;
}
Exemple #17
0
/**
 * The main function.
 */
int main( void )
{
	/* Stop the watchdog timer. */
	WDTCTL = WDTPW + WDTHOLD;
	
	/* Setup MCLK 8MHz and SMCLK 1MHz */
	set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();
	
	/* Enable Interrupts */
	eint();
	
	uart0_init(UART0_CONFIG_1MHZ_115200);
	uart0_register_callback(char_cb);
	printf("CC1100 RXTX test program\r\n");
	
	LEDS_INIT();
	LEDS_OFF();
	
	cc1100_init();
	
	cc1100_cfg_append_status(CC1100_APPEND_STATUS_ENABLE);
	cc1100_cfg_crc_autoflush(CC1100_CRC_AUTOFLUSH_DISABLE);
	cc1100_cfg_white_data(CC1100_DATA_WHITENING_ENABLE);
	cc1100_cfg_crc_en(CC1100_CRC_CALCULATION_ENABLE);
	cc1100_cfg_freq_if(0x0C);
	cc1100_cfg_fs_autocal(CC1100_AUTOCAL_NEVER);
	
	cc1100_cfg_mod_format(CC1100_MODULATION_MSK);
	
	cc1100_cfg_sync_mode(CC1100_SYNCMODE_30_32);
	
	cc1100_cfg_manchester_en(CC1100_MANCHESTER_DISABLE);
	
	printf("CC1100 initialized\r\nType 's' to send a message\r\n");
	
	while(1)
	{
		// Enter RX
		LED_RED_ON();
		cc1100_cmd_idle();
		cc1100_cmd_flush_rx();
		cc1100_cmd_calibrate();
		cc1100_cmd_rx();
		
		cc1100_cfg_gdo0(CC1100_GDOx_SYNC_WORD);
		cc1100_gdo0_int_set_falling_edge();
		cc1100_gdo0_int_clear();
		cc1100_gdo0_int_enable();
		cc1100_gdo0_register_callback(rx_ok);
		
		// Low Power Mode
		LPM0;
		
		// Check for send flag
		if (send == 1) {
			send = 0;
			LED_RED_OFF();
			cc1100_cmd_idle();
			cc1100_cmd_flush_tx();
			cc1100_cmd_calibrate();
			cc1100_gdo0_int_disable();
			
			frameseq ++;
			
			length = sprintf((char *)frame, "Hello World #%i", frameseq);
			
			printf("Sent : %s \r\n", frame);
			
			cc1100_fifo_put(&length, 1);
			cc1100_fifo_put(frame, length);
			
			cc1100_cmd_tx();
			
			// Wait for SYNC word sent
			while (cc1100_gdo0_read() == 0);
			
			// Wait for end of packet
			while (cc1100_gdo0_read() != 0);
		}
		
		// Check for receive flag
		if (receive == 1) {
			receive = 0;
			uint8_t i;

			// verify CRC result
			if ( !(cc1100_status_crc_lqi() & 0x80) ) {
				continue;
			}

			cc1100_fifo_get(&length, 1);
			
			if (length > 60) {
				continue;
			}
			
			cc1100_fifo_get(frame, length+2);

			uint16_t rssi = (uint16_t)frame[length];
			int16_t rssi_d;

			if (rssi >= 128)
				rssi_d = (rssi-256)-140;
			else
				rssi_d = rssi-140;

			printf("Frame received with RSSI=%d.%d dBm: ", rssi_d, 5*(rssi_d&0x1));
			for (i=0; i<length; i++) {
				printf("%c",frame[i]);
			}
			printf("\r\n");

			LED_GREEN_TOGGLE();
		}
	}
	
	return 0;
}
Exemple #18
0
/**
 * Monitor the motor and control it's speed.
 */
void bldc_run() {

    //wdt_enable(WDTO_2S);

    uint16_t bldc_stop_detect_timer = timer_new_sw_ms(64);
    uint16_t speed_report = timer_new_sw_ms(50);
    while (1) {
        wdt_reset();

        static uint8_t uart_cmd = 0;
        uint8_t ch = 0;
        if (getch((char*) &ch) == UART_SUCCESS) {
            if (ch <= '9' && ch >= '1') {
                ch = ch - '0';
                ch = ((uint16_t) ch) * 255 / 9;
                bldc_set_pwm(uart_cmd = ch);

                print_str("cmd:");
                print_number(ch, 10);
                print('\n');
            } else if (ch == ',') {
                print_str("=");
                bldc_phase = 0;
                bldc_old_phase = bldc_phase;
                DISABLE_BEMF_INT();
                bldc_set_pwm(5);
                bldc_pwm = 0;
                bldc_running = 0;
                bldc_set_comm();
                bldc_cnt_comm = 0;
            } else if (ch == '.') {
                do {
                    bldc_phase++;
                    bldc_phase %= 6;
                    bldc_set_comm();
                    bldc_cnt_comm++;
                    if (BEMF) {
                        LED_GREEN_TOGGLE();
                    }
                    for (int ee = 0; ee < 20 * 10; ee++)
                        timer_wait(100);
                } while (bldc_phase != 0);
                bldc_running = 0;
                bldc_old_phase = bldc_phase;
                print_str("stop.\n");
                print_number(bldc_cnt_comm, 10);
            } else {
                // echo
                while (!(UCSRA & (1 << UDRE)))
                    ;
                UDR = ch;

                print_str("stop.\n");
                bldc_set_pwm(0);
                LED_RED_ON();
                DISABLE_BEMF_INT();
                bldc_running = 0;
                SET_ALL_OFF();
                uart_cmd = 0;
            }
        }

        if (bldc_old_phase != bldc_phase) {
            bldc_stop_detect_timer = timer_new_sw_ms(125);
            bldc_running = 1;
            bldc_old_phase = bldc_phase;
        }

        if (bldc_running && timer_sw_check(bldc_stop_detect_timer)) {
            print_str("stalled\n");
            LED_RED_ON();
            DISABLE_BEMF_INT();
            bldc_running = 0;
            SET_ALL_OFF();
        }

        if (!bldc_running) {
            LED_GREEN_OFF();
            bldc_do_start = (bldc_pwm != 0);
        }

        if (bldc_running && timer_sw_check(speed_report)) {
            const uint16_t dt = 20; //ms
            speed_report = timer_new_sw_ms(dt);
            static uint16_t previous_cnt = 0;
            uint32_t rotations = (bldc_cnt_comm - previous_cnt);
            uint32_t rps = rotations * (1000L / dt) / 66;

            bldc_set_pwm(uart_cmd);

            print_number(rps, 10);
            print('\n');
            previous_cnt = bldc_cnt_comm;
        }

        if (bldc_do_start) {
            LED_RED_OFF();
            bldc_do_start = 0;
            print_str("starting...");
            if (bldc_start()) {
                print_str("done.\n");
                LED_GREEN_ON();
                bldc_running = 1;
                BEMF_TOGGLE_INT();
                ENABLE_BEMF_INT();
                bldc_set_pwm(PWM_MIN);
                bldc_stop_detect_timer = timer_new_sw_ms(75);
                while (!timer_sw_check(bldc_stop_detect_timer)) {
                    asm("nop");
                }
                bldc_old_phase = 7;
            } else
                bldc_do_start = 1;
        }
    }
}