Ejemplo n.º 1
0
void radio_init(void)
{
    TRACE_OUTS("radio_init\n");

    //gpio_init(); done by spi_init at moment
    spi_init(&radioConfig);

    gpio_setout(RESET);
    gpio_low(RESET);
    gpio_setout(LED_RED);
    gpio_low(LED_RED);
    gpio_setout(LED_GREEN);
    gpio_low(LED_GREEN);

    TRACE_OUTS("reset...\n");
    radio_reset();

    TRACE_OUTS("reading radiover...\n");
    uint8_t rv = radio_get_ver();
    TRACE_OUTN(rv);
    TRACE_NL();
    if (rv < EXPECTED_RADIOVER) //TODO: make this ASSERT()
    {
        TRACE_OUTS("warning:unexpected radio ver<min\n");
        //TRACE_FAIL("unexpected radio ver<min\n");
    }
    else if (rv > EXPECTED_RADIOVER)
    {
        TRACE_OUTS("warning:unexpected radio ver>exp\n");
    }

    radio_standby();
}
Ejemplo n.º 2
0
void radio_reset(void)
{
    gpio_high(RESET);
    delayms(150);

    gpio_low(RESET);
    delayus(100);
}
Ejemplo n.º 3
0
static void _change_mode(uint8_t mode)
{
    HRF_writereg(HRF_ADDR_OPMODE, mode);
    _wait_ready();
    gpio_low(LED_GREEN); // TX OFF
    gpio_low(LED_RED);   // RX OFF

    if (mode == HRF_MODE_TRANSMITTER)
    {
        _wait_txready();
        gpio_high(LED_RED);   // TX ON
    }
    else if (mode == HRF_MODE_RECEIVER)
    {
        gpio_high(LED_GREEN); // RX ON
    }
    radio_data.mode = mode;
}
Ejemplo n.º 4
0
/**
 * Send a command strobe (one-byte register access that initiates an action)
 *
 * @returns status byte
 */
uint8_t cc2500_send_strobe(uint8_t reg) {
	uint8_t status = 0;
	
	gpio_low(cs_pin);
	status = spi_write_byte(SPIx, reg);
	gpio_high(cs_pin);
	
	return status;
}
Ejemplo n.º 5
0
/**
 * Access a configuration register on the CC2500
 * NOT used for multi-byte registers or command strobes
 *
 * @returns status byte for writes, or value for reads
 */
uint8_t cc2500_write_register(uint8_t reg, uint8_t val) {
	uint8_t status = 0;
	
	gpio_low(cs_pin);
	spi_write_byte(SPIx, reg);
	status = spi_write_byte(SPIx, val);
	gpio_high(cs_pin);
	
	return status;
}
Ejemplo n.º 6
0
void blink(const ff_gpio *gpio)
{
	int i;

	printf("blink\n");

	gpio_input(gpio);
	gpio_output(gpio);

	printf("Start loop\n");
	for (i = 0; i < 10; ++i)
	{
		gpio_high(gpio);
		sleep(1);
		gpio_low(gpio);
		sleep(1);
	}
}
Ejemplo n.º 7
0
void spi_init(SPI_CONFIG* pConfig)
{
  /* It's a standalone library, so init GPIO also */
  gpio_init();
  memcpy(&config, pConfig, sizeof(SPI_CONFIG));

  //TODO: Implement CPHA1
  if (config.cpha != 0)
  {
    TRACE_FAIL("error: CPHA 1 not yet supported");
  }

  gpio_setout(config.sclk);
  CLOCK_IDLE();

  gpio_setout(config.mosi);
  gpio_low(config.mosi);
  gpio_setin(config.miso);

  gpio_setout(config.cs);
  NOT_SELECTED();
}
Ejemplo n.º 8
0
/*
 * Configures all peripherals, then enters an infinite loop that calls the screen draw functions.
 * 
 * Notes: Most of the constants used in this file are defined in /settings.h
 *        The F0 is rated for 48MHz but is being overclocked to 64MHz.
 *        The peripherals currently used (GPIOs, SPI, USART, Timers and ADC) tolerate it.
 */
void main(void) {
    // setup the LCD
    lcd_tft1p4705_setup(LCD_DATA_PORT,
                        LCD_CS_PIN,
                        LCD_RS_PIN,
                        LCD_WR_PIN,
                        LCD_RD_PIN,
                        LCD_RESET_PIN);

    // setup the four push buttons, switch common = gnd
    gpio_setup(PUSHBUTTON_LEFT_PIN, INPUT, PUSH_PULL, FIFTY_MHZ, PULL_UP, AF0);
    exti_setup(PUSHBUTTON_LEFT_PIN, FALLING_EDGE);

    gpio_setup(PUSHBUTTON_RIGHT_PIN, INPUT, PUSH_PULL, FIFTY_MHZ, PULL_UP, AF0);
    exti_setup(PUSHBUTTON_RIGHT_PIN, FALLING_EDGE);

    gpio_setup(PUSHBUTTON_UP_PIN, INPUT, PUSH_PULL, FIFTY_MHZ, PULL_UP, AF0);
    exti_setup(PUSHBUTTON_UP_PIN, FALLING_EDGE);

    gpio_setup(PUSHBUTTON_DOWN_PIN, INPUT, PUSH_PULL, FIFTY_MHZ, PULL_UP, AF0);
    exti_setup(PUSHBUTTON_DOWN_PIN, FALLING_EDGE);
	
    // setup the PWM timer
    timer_pwm_setup(PWM_TIMER_PERIPH,
                    PWM_TIMER_PRESCALER,
                    PWM_TIMER_PERIOD,
                    FOUR_CHANNELS,
                    PWM_TIMER_CH1_PIN,
                    PWM_TIMER_CH2_PIN,
                    PWM_TIMER_CH3_PIN,
                    PWM_TIMER_CH4_PIN);

    // setup the CC2500 RF module
    cc2500_setup(CC2500_SPI_PERIPH,
                 CC2500_CLK_PIN,
                 CC2500_MISO_PIN,
                 CC2500_MOSI_PIN,
                 CC2500_CS_PIN);

    // setup the Bluetooth SPP module (RS232)
    rs232_setup(HC05_USART_PERIPH,
                HC05_RX_MCU_TX_PIN,
                HC05_BAUD_RATE);

    // make HC05 PIO11 pin (UART/AT mode select pin) low to select UART mode, then write test string
    gpio_setup(HC05_PIO11_PIN, OUTPUT, PUSH_PULL, FIFTY_MHZ, NO_PULL, AF0);
    gpio_low(HC05_PIO11_PIN);
    rs232_write_string(HC05_USART_PERIPH, "test\n");

    // setup the ADC, sample at 100Hz
    timer_timebase_setup(TIM1, 48000, 10, 0); // 48MHz/48k/10 = 100Hz update events, 0 = disable interrupt
    adc_setup(CLOCK_TIM1, 10,                 // clock ADC with TIM1, using 10 ADC channels
              TOUCHSCREEN_YD_PIN,
              TOUCHSCREEN_XL_PIN,
              TOUCHSCREEN_YU_PIN,
              TOUCHSCREEN_XR_PIN,
              ADC_BREAKOUT_PIN,
              VOLTAGE_SENSE_PIN,
              CURRENT1_SENSE_PIN,
              CURRENT2_SENSE_PIN,
              CURRENT3_SENSE_PIN,
              CURRENT4_SENSE_PIN);

    // read calibration constants from flash (page 63) to RAM
    struct PersistentData* ptr = (struct PersistentData*) 0x0800FC00;
    voltageCalibrationFactor = ptr->voltageCalibrationFactor;
    current1CalibrationFactor = ptr->current1CalibrationFactor;
    current2CalibrationFactor = ptr->current2CalibrationFactor;
    current3CalibrationFactor = ptr->current3CalibrationFactor;
    current4CalibrationFactor = ptr->current4CalibrationFactor;
    if(ptr->touchMinXCalibrationFactor < 500) {
        touchMinXCalibrationFactor = ptr->touchMinXCalibrationFactor;
        touchMaxXCalibrationFactor = ptr->touchMaxXCalibrationFactor;
        touchMinYCalibrationFactor = ptr->touchMinYCalibrationFactor;
        touchMaxYCalibrationFactor = ptr->touchMaxYCalibrationFactor;
    }

    // draw the current screen
    while(1) {
        if(currentScreen == SWEEP)
            drawSweepScreen();
        else if(currentScreen == THREE_POS)
            draw3posScreen();
        else if(currentScreen == TWO_POS)
            draw2posScreen();
        else if(currentScreen == ONE_POS)
            draw1posScreen();
        else if(currentScreen == SPEC_AN_LIVE)
            drawSpecAnLiveScreen();
        else if(currentScreen == SPEC_AN_WATERFALL)
            drawSpecAnWaterfallScreen();
        else if(currentScreen == CALIBRATION)
            drawCalibrationScreen();
        else if(currentScreen == GAME)
            drawGameScreen();
    }
}