From: ukw Date: Mon, 15 Sep 2014 10:46:02 +0000 (+0000) Subject: Changed irmp_protocol_names to PROGMEM types, added UART routines to main.c X-Git-Tag: irmp-libopencm3-pre-1~45 X-Git-Url: http://cloudbase.mooo.com/gitweb/irmp.git/commitdiff_plain/622f5f5988ba7b2cba507f65050ec09533535b12?hp=7fe8188d6871371baf83a08d1ab42c094525c04b Changed irmp_protocol_names to PROGMEM types, added UART routines to main.c git-svn-id: svn://mikrocontroller.net/irmp@144 aeb2e35e-bfc4-4214-b83c-9e8de998ed28 --- diff --git a/irmp.c b/irmp.c index 5b25eea..18b523a 100644 --- a/irmp.c +++ b/irmp.c @@ -3,11 +3,9 @@ * * Copyright (c) 2009-2014 Frank Meyer - frank(at)fli4l.de * - * $Id: irmp.c,v 1.161 2014/07/21 08:58:58 fm Exp $ + * $Id: irmp.c,v 1.162 2014/09/15 10:27:37 fm Exp $ * - * ATMEGA88 @ 8 MHz - * - * Supported mikrocontrollers: + * Supported AVR mikrocontrollers: * * ATtiny87, ATtiny167 * ATtiny45, ATtiny85 @@ -498,52 +496,96 @@ static void (*irmp_callback_ptr) (uint8_t); *--------------------------------------------------------------------------------------------------------------------------------------------------- */ #if defined(UNIX_OR_WINDOWS) || IRMP_PROTOCOL_NAMES == 1 -const char * -irmp_protocol_names[IRMP_N_PROTOCOLS + 1] = +static const char proto_unknown[] PROGMEM = "UNKNOWN"; +static const char proto_sircs[] PROGMEM = "SIRCS"; +static const char proto_nec[] PROGMEM = "NEC"; +static const char proto_samsung[] PROGMEM = "SAMSUNG"; +static const char proto_matsushita[] PROGMEM = "MATSUSH"; +static const char proto_kaseikyo[] PROGMEM = "KASEIKYO"; +static const char proto_recs80[] PROGMEM = "RECS80"; +static const char proto_rc5[] PROGMEM = "RC5"; +static const char proto_denon[] PROGMEM = "DENON"; +static const char proto_rc6[] PROGMEM = "RC6"; +static const char proto_samsung32[] PROGMEM = "SAMSG32"; +static const char proto_apple[] PROGMEM = "APPLE"; +static const char proto_recs80ext[] PROGMEM = "RECS80EX"; +static const char proto_nubert[] PROGMEM = "NUBERT"; +static const char proto_bang_olufsen[] PROGMEM = "BANG OLU"; +static const char proto_grundig[] PROGMEM = "GRUNDIG"; +static const char proto_nokia[] PROGMEM = "NOKIA"; +static const char proto_siemens[] PROGMEM = "SIEMENS"; +static const char proto_fdc[] PROGMEM = "FDC"; +static const char proto_rccar[] PROGMEM = "RCCAR"; +static const char proto_jvc[] PROGMEM = "JVC"; +static const char proto_rc6a[] PROGMEM = "RC6A"; +static const char proto_nikon[] PROGMEM = "NIKON"; +static const char proto_ruwido[] PROGMEM = "RUWIDO"; +static const char proto_ir60[] PROGMEM = "IR60"; +static const char proto_kathrein[] PROGMEM = "KATHREIN"; +static const char proto_netbox[] PROGMEM = "NETBOX"; +static const char proto_nec16[] PROGMEM = "NEC16"; +static const char proto_nec42[] PROGMEM = "NEC42"; +static const char proto_lego[] PROGMEM = "LEGO"; +static const char proto_thomson[] PROGMEM = "THOMSON"; +static const char proto_bose[] PROGMEM = "BOSE"; +static const char proto_a1tvbox[] PROGMEM = "A1TVBOX"; +static const char proto_ortek[] PROGMEM = "ORTEK"; +static const char proto_telefunken[] PROGMEM = "TELEFUNKEN"; +static const char proto_roomba[] PROGMEM = "ROOMBA"; +static const char proto_rcmm32[] PROGMEM = "RCMM32"; +static const char proto_rcmm24[] PROGMEM = "RCMM24"; +static const char proto_rcmm12[] PROGMEM = "RCMM12"; +static const char proto_speaker[] PROGMEM = "SPEAKER"; +static const char proto_lgair[] PROGMEM = "LGAIR"; +static const char proto_samsung48[] PROGMEM = "SAMSG48"; +static const char proto_radio1[] PROGMEM = "RADIO1"; + +const char * const +irmp_protocol_names[IRMP_N_PROTOCOLS + 1] PROGMEM = { - "UNKNOWN", - "SIRCS", - "NEC", - "SAMSUNG", - "MATSUSH", - "KASEIKYO", - "RECS80", - "RC5", - "DENON", - "RC6", - "SAMSG32", - "APPLE", - "RECS80EX", - "NUBERT", - "BANG OLU", - "GRUNDIG", - "NOKIA", - "SIEMENS", - "FDC", - "RCCAR", - "JVC", - "RC6A", - "NIKON", - "RUWIDO", - "IR60", - "KATHREIN", - "NETBOX", - "NEC16", - "NEC42", - "LEGO", - "THOMSON", - "BOSE", - "A1TVBOX", - "ORTEK", - "TELEFUNKEN", - "ROOMBA", - "RCMM32", - "RCMM24", - "RCMM12", - "SPEAKER", - "LGAIR", - "SAMSG48", - "RADIO1" + proto_unknown, + proto_sircs, + proto_nec, + proto_samsung, + proto_matsushita, + proto_kaseikyo, + proto_recs80, + proto_rc5, + proto_denon, + proto_rc6, + proto_samsung32, + proto_apple, + proto_recs80ext, + proto_nubert, + proto_bang_olufsen, + proto_grundig, + proto_nokia, + proto_siemens, + proto_fdc, + proto_rccar, + proto_jvc, + proto_rc6a, + proto_nikon, + proto_ruwido, + proto_ir60, + proto_kathrein, + proto_netbox, + proto_nec16, + proto_nec42, + proto_lego, + proto_thomson, + proto_bose, + proto_a1tvbox, + proto_ortek, + proto_telefunken, + proto_roomba, + proto_rcmm32, + proto_rcmm24, + proto_rcmm12, + proto_speaker, + proto_lgair, + proto_samsung48, + proto_radio1 }; #endif @@ -737,79 +779,6 @@ irmp_uart_putc (unsigned char ch) #define ENDBITS 1000 // number of sequenced highbits to detect end #define DATALEN 700 // log buffer size -#if 0 // old log routine - -static void -irmp_log (uint8_t val) -{ - static uint8_t buf[DATALEN]; // logging buffer - static uint16_t buf_idx; // number of written bits - static uint8_t startcycles; // current number of start-zeros - static uint16_t cnt; // counts sequenced highbits - to detect end - - if (! val && (startcycles < STARTCYCLES) && !buf_idx) // prevent that single random zeros init logging - { - startcycles++; - } - else - { - startcycles = 0; - - if (! val || (val && buf_idx != 0)) // start or continue logging on "0", "1" cannot init logging - { - if (buf_idx < DATALEN * 8) // index in range? - { // yes - if (val) - { - buf[(buf_idx / 8)] |= (1<<(buf_idx % 8)); // set bit - } - else - { - buf[(buf_idx / 8)] &= ~(1<<(buf_idx % 8)); // reset bit - } - - buf_idx++; - } - - if (val) - { // if high received then look at log-stop condition - cnt++; - - if (cnt > ENDBITS) - { // if stop condition is true, output on uart - uint16_t i; - - for (i = 0; i < STARTCYCLES; i++) - { - irmp_uart_putc ('0'); // the ignored starting zeros - } - - for (i = 0; i < (buf_idx - ENDBITS + 20) / 8; i++) // transform bitset into uart chars - { - uint8_t d = buf[i]; - uint8_t j; - - for (j = 0; j < 8; j++) - { - irmp_uart_putc ((d & 1) + '0'); - d >>= 1; - } - } - - irmp_uart_putc ('\n'); - buf_idx = 0; - } - } - else - { - cnt = 0; - } - } - } -} - -#else // new log routine - static void irmp_log (uint8_t val) { @@ -898,8 +867,6 @@ irmp_log (uint8_t val) } } -#endif - #else #define irmp_log(val) #endif //IRMP_LOGGING diff --git a/irmp.h b/irmp.h index 8b61f25..cda737c 100644 --- a/irmp.h +++ b/irmp.h @@ -3,9 +3,7 @@ * * Copyright (c) 2009-2014 Frank Meyer - frank(at)fli4l.de * - * $Id: irmp.h,v 1.88 2014/07/21 08:58:58 fm Exp $ - * - * ATMEGA88 @ 8 MHz + * $Id: irmp.h,v 1.89 2014/09/15 10:27:38 fm Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -178,7 +176,7 @@ extern uint8_t irmp_is_busy (void); extern uint8_t irmp_ISR (void); #if IRMP_PROTOCOL_NAMES == 1 -extern const char * irmp_protocol_names[IRMP_N_PROTOCOLS + 1]; +extern const char * const irmp_protocol_names[IRMP_N_PROTOCOLS + 1] PROGMEM; #endif #if IRMP_USE_CALLBACK == 1 diff --git a/irmpconfig.h b/irmpconfig.h index 218e939..b9a73fd 100644 --- a/irmpconfig.h +++ b/irmpconfig.h @@ -6,7 +6,7 @@ * Copyright (c) 2009-2014 Frank Meyer - frank(at)fli4l.de * Extensions for PIC 12F1820 W.Strobl 2014-07-20 * - * $Id: irmpconfig.h,v 1.117 2014/07/21 08:56:39 fm Exp $ + * $Id: irmpconfig.h,v 1.119 2014/09/15 10:31:22 fm Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/irmpsystem.h b/irmpsystem.h index 575bfda..d19a0a7 100644 --- a/irmpsystem.h +++ b/irmpsystem.h @@ -3,7 +3,7 @@ * * Copyright (c) 2009-2014 Frank Meyer - frank(at)fli4l.de * - * $Id: irmpsystem.h,v 1.13 2014/07/21 08:58:58 fm Exp $ + * $Id: irmpsystem.h,v 1.14 2014/09/15 10:27:38 fm Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,6 +37,7 @@ # include # define ARM_STM32 # define ARM_STM32F10X +# define F_CPU (SysCtlClockGet()) #elif defined(STM32F4XX) // ARM STM32 # include # define ARM_STM32 @@ -95,6 +96,13 @@ typedef unsigned short uint16_t; # define PROGMEM volatile # define memcpy_P memcpy # define APP_SYSTICKS_PER_SEC 32 +#elif defined(ARM_STM32F10X) +# include "stm32f10x_gpio.h" +# include "stm32f10x_rcc.h" +# include "stm32f10x_tim.h" +# include "misc.h" +# define PROGMEM +# define memcpy_P memcpy #else # define PROGMEM # define memcpy_P memcpy diff --git a/irsnd.c b/irsnd.c index 447971e..00f80e3 100644 --- a/irsnd.c +++ b/irsnd.c @@ -3,7 +3,7 @@ * * Copyright (c) 2010-2014 Frank Meyer - frank(at)fli4l.de * - * Supported mikrocontrollers: + * Supported AVR mikrocontrollers: * * ATtiny87, ATtiny167 * ATtiny45, ATtiny85 @@ -13,7 +13,7 @@ * ATmega164, ATmega324, ATmega644, ATmega644P, ATmega1284, ATmega1284P * ATmega88, ATmega88P, ATmega168, ATmega168P, ATmega328P * - * $Id: irsnd.c,v 1.81 2014/07/21 08:58:58 fm Exp $ + * $Id: irsnd.c,v 1.82 2014/09/15 10:27:38 fm Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/irsnd.h b/irsnd.h index e9e1736..eaff6c3 100644 --- a/irsnd.h +++ b/irsnd.h @@ -3,9 +3,7 @@ * * Copyright (c) 2010-2014 Frank Meyer - frank(at)fli4l.de * - * $Id: irsnd.h,v 1.19 2014/07/21 08:58:58 fm Exp $ - * - * ATMEGA88 @ 8 MHz + * $Id: irsnd.h,v 1.20 2014/09/15 10:27:38 fm Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/irsndconfig.h b/irsndconfig.h index 97d1d35..ad4976d 100644 --- a/irsndconfig.h +++ b/irsndconfig.h @@ -5,9 +5,7 @@ * * Copyright (c) 2010-2014 Frank Meyer - frank(at)fli4l.de * - * $Id: irsndconfig.h,v 1.62 2014/07/21 08:56:39 fm Exp $ - * - * ATMEGA88 @ 8 MHz + * $Id: irsndconfig.h,v 1.63 2014/09/15 10:27:38 fm Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/main.c b/main.c index 9c1cc24..538e2fa 100644 --- a/main.c +++ b/main.c @@ -3,7 +3,7 @@ * * Copyright (c) 2009-2014 Frank Meyer - frank(at)fli4l.de * - * $Id: main.c,v 1.19 2014/07/21 08:58:59 fm Exp $ + * $Id: main.c,v 1.20 2014/09/15 10:27:38 fm Exp $ * * This demo module is runnable on AVRs and LM4F120 Launchpad (ARM Cortex M4) * @@ -29,7 +29,126 @@ */ #if defined (ATMEL_AVR) -void +#include "irmp.h" +#define BAUD 9600L +#include + +#ifdef UBRR0H + +#define UART0_UBRRH UBRR0H +#define UART0_UBRRL UBRR0L +#define UART0_UCSRA UCSR0A +#define UART0_UCSRB UCSR0B +#define UART0_UCSRC UCSR0C +#define UART0_UDRE_BIT_VALUE (1<> 4); + *xx++ = itox (i & 0x0F); + *xx = '\0'; +} + +static void timer1_init (void) { #if defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) // ATtiny45 / ATtiny85: @@ -69,21 +188,45 @@ ISR(COMPA_VECT) // T int main (void) { - IRMP_DATA irmp_data; + IRMP_DATA irmp_data; + char buf[3]; irmp_init(); // initialize irmp timer1_init(); // initialize timer1 + uart_init(); // initialize uart + sei (); // enable interrupts for (;;) { if (irmp_get_data (&irmp_data)) { - // ir signal decoded, do something here... - // irmp_data.protocol is the protocol, see irmp.h - // irmp_data.address is the address/manufacturer code of ir sender - // irmp_data.command is the command code - // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h) + uart_puts_P (PSTR("protocol: 0x")); + itoxx (buf, irmp_data.protocol); + uart_puts (buf); + +#if IRMP_PROTOCOL_NAMES == 1 + uart_puts_P (PSTR(" ")); + uart_puts_P (irmp_protocol_names[irmp_data.protocol]); +#endif + + uart_puts_P (PSTR(" address: 0x")); + itoxx (buf, irmp_data.address >> 8); + uart_puts (buf); + itoxx (buf, irmp_data.address & 0xFF); + uart_puts (buf); + + uart_puts_P (PSTR(" command: 0x")); + itoxx (buf, irmp_data.command >> 8); + uart_puts (buf); + itoxx (buf, irmp_data.command & 0xFF); + uart_puts (buf); + + uart_puts_P (PSTR(" flags: 0x")); + itoxx (buf, irmp_data.flags); + uart_puts (buf); + + uart_puts_P (PSTR("\r\n")); } } } @@ -189,4 +332,70 @@ void interrupt high_priority high_isr(void) } } +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * STM32: + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#elif defined(ARM_STM32) + +uint32_t +SysCtlClockGet(void) +{ + RCC_ClocksTypeDef RCC_ClocksStatus; + RCC_GetClocksFreq(&RCC_ClocksStatus); + return RCC_ClocksStatus.SYSCLK_Frequency; +} + +void +timer2_init (void) +{ + TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; + NVIC_InitTypeDef NVIC_InitStructure; + RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); + + TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseStructure.TIM_Period = 7; + TIM_TimeBaseStructure.TIM_Prescaler = ((F_CPU / F_INTERRUPTS)/8) - 1; + TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); + + TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); + + NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; + NVIC_Init(&NVIC_InitStructure); + + TIM_Cmd(TIM2, ENABLE); +} + +void +TIM2_IRQHandler(void) // Timer2 Interrupt Handler +{ + TIM_ClearITPendingBit(TIM2, TIM_IT_Update); + (void) irmp_ISR(); // call irmp ISR + // call other timer interrupt routines... +} + +int +main (void) +{ + IRMP_DATA irmp_data; + + irmp_init(); // initialize irmp + timer2_init(); // initialize timer2 + + for (;;) + { + if (irmp_get_data (&irmp_data)) + { + // ir signal decoded, do something here... + // irmp_data.protocol is the protocol, see irmp.h + // irmp_data.address is the address/manufacturer code of ir sender + // irmp_data.command is the command code + // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h) + } + } +} #endif