Esempio n. 1
0
File: main.cpp Progetto: Kreyl/nute
// ================================== Events ===================================
void EVENT_SensorsStateChanged(void) {
    UART_PrintString("Sns: ");
    UART_PrintArrAsHex((uint8_t*)&SnsState, sizeof(SnsState_t));
    if(SnsState.KeyTouched[1]) ERock.TryToActivate(actOne);
    if(SnsState.KeyTouched[2]) ERock.TryToActivate(actTwo);
    //if(SnsState.MagnetNear) ERock.TryToActivate(actTwo);
    if(SnsState.KeyTouched[0] && SnsState.KeyTouched[2]) ERock.TryToActivate(actThree);
}
Esempio n. 2
0
File: main.cpp Progetto: Kreyl/nute
int main(void) {
    UART_Init();
    Delay.ms(100);
    UART_PrintString("Let's rock!\r");

    GeneralInit();

    // ==== Main cycle ====
    while(1) {
        i2cMgr.Task();
        ESnd.Task();
        ESns.Task();
        Leds.Task();
        ERock.Task();
        EIRSirc.Task();
        Lcd.Task();
    } // while(1)
    return 0;
}
Esempio n. 3
0
void HandleInputChar(char c)
{
    int i;
    int result;

    result =  PROTO_HandleInputCharacter(c);
    if (result == RESULT_ERROR) {
        UART_PrintString(kErrorResponse);
    }
    else if( result == RESULT_ACCEPT ) {
        const ProtocolHandler *handler = PROTO_GetCurrentHandler();
        if (handler) {
            switch (handler->id) {
                case PROTO_ID_DEFAULT:
                    UART_PrintString(kOkResponse);
                    UART_PrintString(kNewLine);
                    break;

                case PROTO_ID_SYS:
                    if (PROTO_SYS_GetCommand() == PROTO_SYS_COMMAND_RESET) {
                        UART_PrintString(kOkResponse);
                        while(UART_CheckBusy(LPC_UART) != RESET);
                        NVIC_SystemReset();
                    }
                    else if (PROTO_SYS_GetCommand() == PROTO_SYS_COMMAND_VERSION) {
                        PrintVersionString(UART_WriteChar);
                    }
                    else {
                        UART_PrintString(kNotAvailableResponse);
                    }

                    UART_PrintString(kNewLine);
                    break;

                /*
                    case COMMAND_BACKLITE:
                        UART_PrintString( "+BL\r\n" );
                        backlite_power = PROTO_GetBacklitePower();
                        break;
                */

                case PROTO_ID_SPI:
                    if (0 && PROTO_SPI_GetAction() == PROTO_SPI_ACTION_READ) {
                        int len = PROTO_SPI_GetLength();
                        func_printf_nofloat(UART_WriteChar, "%02X:", len);
                        for (i = 0; i < len; i++) {
                            uint8_t b;
                            b = SPI_ReadByte();
                            func_printf_nofloat(UART_WriteChar, " %02X", b);
                        }
                    }
                    else if (PROTO_SPI_GetAction() == PROTO_SPI_ACTION_WRITE) {
                        uint8_t *data = PROTO_SPI_GetData();
                        int len = PROTO_SPI_GetLength();
                        SPI_Write(data, len);
                        UART_PrintString(kOkResponse);
                    }
                    else {
                        UART_PrintString(kNotAvailableResponse);
                    }

                    UART_PrintString(kNewLine);
                    break;

                case PROTO_ID_RFID:
                    if (PROTO_RF_GetAction() == PROTO_RF_ACTION_READ) {
                        int len = PROTO_RF_GetLength();
                        func_printf_nofloat(UART_WriteChar, "%02X:", len);
                        for (i = 0; i < len; i++) {
                            int addr = PROTO_RF_GetAddress();
                            uint8_t b;

                            if (PROTO_RF_GetMode() == PROTO_RF_MODE_INCREMENT_ADDRESS)
                                addr += i;

                            if (PROTO_RF_GetTarget() == PROTO_RF_TARGET_PORT)
                                b = CL632_SpiReadByte(addr);
                            else if (PROTO_RF_GetTarget() == PROTO_RF_TARGET_MEMORY)
                                CL632_ReadE2(addr, &b, 1);

                            func_printf_nofloat(UART_WriteChar, " %02X", b);
                        }
                    }
                    else if (PROTO_RF_GetAction() == PROTO_RF_ACTION_WRITE) {
                        int addr = PROTO_RF_GetAddress();
                        uint8_t *data = PROTO_RF_GetData();
                        int len = PROTO_RF_GetLength();
                        int same_address = PROTO_RF_GetMode() == PROTO_RF_MODE_SAME_ADDRESS;

                        if (PROTO_RF_GetTarget() == PROTO_RF_TARGET_PORT) {
                            CL632_SpiWrite(addr, same_address, data, len);
                        }
                        else if (PROTO_RF_GetTarget() == PROTO_RF_TARGET_MEMORY) {
                            CL632_WriteE2(addr, data, len);
                        }

                        UART_PrintString(kOkResponse);
                    }
                    else {
                        UART_PrintString(kNotAvailableResponse);
                    }

                    UART_PrintString(kNewLine);
                    break;

                case PROTO_ID_RGB:
                    switch (PROTO_RGB_GetCommand()) {
                        case PROTO_RGB_COMMAND_CAPABILITIES:
                            UART_PrintString("RGB,TRAN");
                            break;

                        case PROTO_RGB_COMMAND_PRINT_SEQUENCE:
                            UART_PrintString("S");
                            for (i = 0; i < SEQ_GetSequenceLength(); i++) {
                                const COMMAND *cmd = &(SEQ_GetSequence()[i]);
                                func_printf_nofloat(UART_WriteChar, " L%d#%02X%02X%02X",
                                        cmd->interval, cmd->color.red, cmd->color.green, cmd->color.blue);
                            }
                            break;

                        case PROTO_RGB_COMMAND_SET_SEQUENCE:
                            SEQ_SetSequence(PROTO_RGB_GetSequence(), PROTO_RGB_GetSequenceLength());
                            UART_PrintString(kOkResponse);
                            break;

                        default:
                            UART_PrintString(kNotAvailableResponse);
                            break;
                    }

                    UART_PrintString(kNewLine);
                    break;
            }
        }
    }
}
Esempio n. 4
0
int main()
{
    UART_CFG_Type uart_config;
    UART_FIFO_CFG_Type uart_fifo_config;
    TIM_TIMERCFG_Type timer_config;
    TIM_MATCHCFG_Type timer_match;
    OS_TID uart_task_id = 0;
    OS_TID activity_task_id = 0;
    uint32_t reset_flags = 0;

    reset_flags = LPC_SYSCON->SYSRSTSTAT;

    SEQ_Initialize();
    PROTO_Reset();
    PROTO_SetHandlers(g_protocol_handlers);

    SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_GPIO, ENABLE);

    // Reset pin
    IOCON_SetPinFunc(IOCON_PIO0_0, PIO0_0_FUN_RESET);

    // Status LED pin
    ACTIVITY_SET_PIN();
    GPIO_SetDir(ACTIVITY_PORT, ACTIVITY_PIN, 1);
    GPIO_ResetBits(ACTIVITY_PORT, ACTIVITY_PIN);

    // Timer activity LED pin
    TIMER_ACTIVITY_SET_PIN();
    GPIO_SetDir(TIMER_ACTIVITY_PORT, TIMER_ACTIVITY_PIN, 1);
    GPIO_ResetBits(TIMER_ACTIVITY_PORT, TIMER_ACTIVITY_PIN);

    // RGB control
    RED_SET_PIN();
    GREEN_SET_PIN();
    BLUE_SET_PIN();
    GPIO_SetDir(RED_PORT, RED_PIN, 1);
    GPIO_SetDir(GREEN_PORT, GREEN_PIN, 1);
    GPIO_SetDir(BLUE_PORT, BLUE_PIN, 1);
    GPIO_ResetBits(RED_PORT, RED_PIN);
    GPIO_ResetBits(GREEN_PORT, GREEN_PIN);
    GPIO_ResetBits(BLUE_PORT, BLUE_PIN);

    timer_config.PrescaleOption = TIM_PRESCALE_TICKVAL;
    timer_config.PrescaleValue = 1;
    TIM_Init(LPC_TMR32B0, TIM_TIMER_MODE, &timer_config);

    timer_match.MatchChannel = 0;
    timer_match.IntOnMatch = ENABLE;
    timer_match.StopOnMatch = DISABLE;
    timer_match.ResetOnMatch = ENABLE;
    timer_match.ExtMatchOutputType = 0;
    timer_match.MatchValue = SystemCoreClock / (TICKS_PER_SECOND * 256);
    TIM_ConfigMatch(LPC_TMR32B0, &timer_match);

    TIM_Cmd(LPC_TMR32B0, ENABLE);
    NVIC_EnableIRQ(TIMER_32_0_IRQn);

    // UART
    IOCON_SetPinFunc(IOCON_PIO1_6, PIO1_6_FUN_RXD);   /* UART RXD - PIO1_6 */
    IOCON_SetPinFunc(IOCON_PIO1_7, PIO1_7_FUN_TXD);   /* UART RXD - PIO1_7 */

    uart_config.Baud_rate = 115200;
    uart_config.Databits = UART_DATABIT_8;
    uart_config.Parity = UART_PARITY_NONE;
    uart_config.Stopbits = UART_STOPBIT_1;

    UART_Init(LPC_UART, &uart_config);

    uart_fifo_config.FIFO_Level = UART_FIFO_TRGLEV0;
    uart_fifo_config.FIFO_ResetRxBuf = ENABLE;
    uart_fifo_config.FIFO_ResetTxBuf = ENABLE;
    UART_FIFOConfig(LPC_UART, &uart_fifo_config);

    UART_TxCmd(LPC_UART, ENABLE);

    // SPI
    CL632_Init();
    // Select page 0 and no paging access
    CL632_SpiWriteByte(0x00, 0x00);
    CL632_SpiWriteByte(0x00, 0x00);

    // LCD
    // LCD backlite control
    LCD_BACKLITE_SET_PIN();
    GPIO_SetDir(LCD_BACKLITE_PORT, LCD_BACKLITE_PIN, 1);
    GPIO_ResetBits(LCD_BACKLITE_PORT, LCD_BACKLITE_PIN);

    // LCD Data bus
    LCD_DATA_SET_PINS();
    GPIO_SetDir(LCD_DATA_PORT, LCD_DATA_BUS, 1);
    GPIO_ResetBits(LCD_DATA_PORT, LCD_DATA_BUS);

    LCD_RS_SET_PIN();
    GPIO_SetDir(LCD_RS_PORT, LCD_RS_PIN, 1);
    GPIO_ResetBits(LCD_RS_PORT, LCD_RS_PIN);

    LCD_RW_SET_PIN();
    GPIO_SetDir(LCD_RW_PORT, LCD_RW_PIN, 1);
    GPIO_ResetBits(LCD_RW_PORT, LCD_RW_PIN);

    LCD_E_SET_PIN();
    GPIO_SetDir(LCD_E_PORT, LCD_E_PIN, 1);
    GPIO_ResetBits(LCD_E_PORT, LCD_E_PIN);

    KS0066_PowerUpDelay();
    KS0066_FunctionSet();
    KS0066_WaitForIdle();
    KS0066_DisplayOnOffControl(KS0066_DISPCTL_DISPLAY_ON);
    KS0066_WaitForIdle();
    KS0066_ClearDisplay();
    KS0066_WaitForIdle();

    CoInitOS();
    GPIO_SetBits(ACTIVITY_PORT, ACTIVITY_PIN);

    uart_task_id = CoCreateTask(uartTask, NULL, UART_TASK_PRIORITY,
            GetStackTop(uartTaskStack), GetStackSize(uartTaskStack));

    activity_task_id = CoCreateTask(activityTask, NULL, ACTIVITY_TASK_PRIORITY,
            GetStackTop(activityTaskStack), GetStackSize(activityTaskStack));

    if (uart_task_id == E_CREATE_FAIL || activity_task_id == E_CREATE_FAIL) {
        UART_PrintString("INIT ERROR");
        UART_PrintString(kNewLine);
    }

    if (reset_flags & 0x01)
        UART_PrintString("RST:PU");
    else if (reset_flags & 0x02)
        UART_PrintString("RST:RST");
    else if (reset_flags & 0x04)
        UART_PrintString("RST:WDT");
    else if (reset_flags & 0x08)
        UART_PrintString("RST:BOD");
    else if (reset_flags & 0x10)
        UART_PrintString("RST:SOFT");
    else
        UART_PrintString("RST");

    UART_PrintString(kNewLine);

    PrintVersionString(UART_WriteChar);
    UART_PrintString(kNewLine);
    func_printf_nofloat(UART_WriteChar, "COOS:%d\r\n", CoGetOSVersion());

    KS0066_WriteString("V:" __DATE__ " " __TIME__, KS0066_WRAP_FLAG);

    CoStartOS();

    //while (1) {
    //}

    return 0;
}
Esempio n. 5
0
/**	@brief	With this function the Task Overflow Led on the emphase mainboard
			can be turned on.
	@todo	What functionality should be offered here?
*******************************************************************************/
void DEBUG_WelcomeMsg(void)
{
	#if defined(HIGHDEBUG) || defined(LOWDEBUG)
	/* print welcome message */
	UART_PrintString("\n\n\n");
	UART_PrintString("#####################################################################################\n");
	UART_PrintString("#                         NONLINEAR LABS - Emphase Keyboard                         #\n");
	UART_PrintString("####################################################################################\n\n");
	UART_PrintString(__DATE__);
	UART_PrintString(" - ");
	UART_PrintString(__TIME__);
	UART_PrintString("\n\n");
	/* print sytem clock in Mhz */
	UART_PrintString("SystemCoreClock:      ");
	itoa((SystemCoreClock/1000000), buf, 10);
	UART_PrintString(buf);
	UART_PrintString(" MHz \n");
	/* print system tick time */
	UART_PrintString("SysTick every:        ");
	itoa((SystemCoreClock/SYSTICK_VAL), buf, 10);
	UART_PrintString(buf);
	UART_PrintString(" us\n\n");
	#endif

	#if defined(LOWDEBUG)
	UART_PrintString("ND_GLOBAL_Init:       Init succeeded.\n\n");
	#endif
}