/**
 * Initializes the specified serial port
 * Lua Params:
 * port - the serial port to initialize
 *        (SERIAL_USB, SERIAL_GPS, SERIAL_TELEMETRY, SERIAL_WIRELESS, SERIAL_AUX) (defaults to SERIAL_AUX)
 * baud - Baud Rate (defaults to 115200)
 * bits - Number of bit in the message (8 or 7) (defaults to 8)
 * parity - (1 = Even Parity, 2 = Odd Parity, 0 = No Parity) (defaults to No Parity)
 * stopBits - number of stop bits (1 or 2) (defaults to 1)
 *
 * Lua Returns:
 * 1 if successful; -1 if parameter error
 */
int Lua_InitSerial(lua_State *L)
{
    int params = lua_gettop(L);

    serial_id_t port = LUA_DEFAULT_SERIAL_PORT;
    uint32_t baud = LUA_DEFAULT_SERIAL_BAUD;
    uint8_t bits  = LUA_DEFAULT_SERIAL_BITS;
    uint8_t parity = LUA_DEFAULT_SERIAL_PARITY;
    uint8_t stop_bits = LUA_DEFAULT_SERIAL_STOP_BITS;

    switch(params) {
    case 5:
        stop_bits = lua_tointeger(L, 5);
    case 4:
        parity = lua_tointeger(L, 4);
    case 3:
        bits = lua_tointeger(L, 3);
    case 2:
        baud = lua_tointeger(L, 2);
    case 1:
        port = lua_tointeger(L, 1);
    case 0:
        configure_serial(port, bits, parity, stop_bits, baud);
        lua_pushnumber(L, 1);
        break;
    default:
        lua_pushnumber(L, -1);
        break;
    }
    return 1;
}
Beispiel #2
0
int main(void)
{

  // Set the system clock source to HS XOSC and max CPU speed,
  // ref. [clk]=>[clk_xosc.c]
  SLEEP &= ~SLEEP_OSC_PD;
  while( !(SLEEP & SLEEP_XOSC_S) );
  CLKCON = (CLKCON & ~(CLKCON_CLKSPD | CLKCON_OSC)) | CLKSPD_DIV_1;
  while (CLKCON & CLKCON_OSC);
  SLEEP |= SLEEP_OSC_PD;


  // init LEDS
  HARDWARE_LED_INIT;       // see hardware.h
  led_set_state(0, 0); //GREEN_LED = 0;
  led_set_state(1, 0); //BLUE_LED = 0;

  // Global interrupt enable
  init_timer();
  EA = 1;

  //LED test
  led_set_state(0, 1); //GREEN_LED = 1;
  delay(1000);
  led_set_state(0, 0); //GREEN_LED = 0;
  led_set_state(1, 1); //BLUE_LED = 1;
  delay(1000);
  led_set_state(1, 0); //BLUE_LED = 0;

  configure_radio();
  configure_serial();

  while(1) {
    //led_set_state(0,2);
    get_command();
  }
}