X-Git-Url: http://cloudbase.mooo.com/gitweb/irmp-demo.git/blobdiff_plain/43e6d5ec386f052ba7f2830e23fae0b4d474746b..1cb9eb4284372766bb9a4a0dad7727add2491a6b:/irsnd-main.c diff --git a/irsnd-main.c b/irsnd-main.c index 3387439..38c0da6 100644 --- a/irsnd-main.c +++ b/irsnd-main.c @@ -42,9 +42,9 @@ #define LED_PORT_RCC RCC_GPIOC #if DEBUG_IRMP_TIMER_INT -#define DEBUG_LED_PORT GPIOA -#define DEBUG_LED_PIN GPIO2 -#define DEBUG_LED_PORT_RCC RCC_GPIOA +#define DEBUG_LED_PORT GPIOB +#define DEBUG_LED_PIN GPIO0 +#define DEBUG_LED_PORT_RCC RCC_GPIOB #endif /** @@ -85,10 +85,10 @@ static void led_off(void) static void debug_led_on(void) { #if DEBUG_IRMP_TIMER_INT -# if USE_OPENCM3_API /* Using API functions: */ +# if USE_OPENCM3_API /* Using API functions: */ gpio_clear(DEBUG_LED_PORT, DEBUG_LED_PIN); #else - GPIO_BRR(GPIOA) = GPIO2; + GPIO_BRR(DEBUG_LED_PORT) = DEBUG_LED_PIN; # endif #endif } @@ -96,10 +96,10 @@ static void debug_led_on(void) static void debug_led_off(void) { #if DEBUG_IRMP_TIMER_INT -# if USE_OPENCM3_API /* Using API functions: */ +# if USE_OPENCM3_API /* Using API functions: */ gpio_set(DEBUG_LED_PORT, DEBUG_LED_PIN); #else - GPIO_BSRR(GPIOA) = GPIO2; + GPIO_BSRR(DEBUG_LED_PORT) = DEBUG_LED_PIN; # endif #endif } @@ -133,10 +133,10 @@ uint32_t timer_internal_clock_get(uint32_t timer_peripheral) #ifdef STM32F0 timer_frequency = rcc_apb1_frequency; #else - if (timer_peripheral < PERIPH_BASE_APB2) + if (timer_peripheral < PERIPH_BASE_APB2) { timer_frequency = rcc_apb1_frequency; - } else { + } else { timer_frequency = rcc_apb2_frequency; } #endif /* STM32F0 */ @@ -144,7 +144,7 @@ uint32_t timer_internal_clock_get(uint32_t timer_peripheral) if (timer_frequency != rcc_ahb_frequency) timer_frequency *= 2; - return timer_frequency; + return timer_frequency; } /** @@ -155,30 +155,31 @@ void irsnd_tick_timer_init(void) #if DEBUG_IRMP_TIMER_INT /* Output pin for debugging */ rcc_periph_clock_enable(DEBUG_LED_PORT_RCC); + gpio_set(DEBUG_LED_PORT, DEBUG_LED_PIN); gpio_set_mode(DEBUG_LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, DEBUG_LED_PIN); #endif - /* Enable timer clock. */ + /* Enable timer clock. */ rcc_periph_clock_enable(IRSND_TICK_TIMER_RCC); nvic_set_priority(NVIC_IRSND_TICK_TIMER_IRQ, 4*16); - nvic_enable_irq(NVIC_IRSND_TICK_TIMER_IRQ); - -#if USE_OPENCM3_API /* Using API functions: */ - - /* Timer global mode: - * - No divider - * - Alignment edge - * - Direction up - * (These are actually default values after reset, so this call - * is strictly unnecessary, but demos the api for alternative settings) - */ - timer_set_mode(IRSND_TICK_TIMER, TIM_CR1_CKD_CK_INT, + nvic_enable_irq(NVIC_IRSND_TICK_TIMER_IRQ); + +#if USE_OPENCM3_API /* Using API functions: */ + + /* Timer global mode: + * - No divider + * - Alignment edge + * - Direction up + * (These are actually default values after reset, so this call + * is strictly unnecessary, but demos the api for alternative settings) + */ + timer_set_mode(IRSND_TICK_TIMER, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); - timer_set_period(IRSND_TICK_TIMER, timer_internal_clock_get(IRSND_TICK_TIMER) / F_INTERRUPTS - 1); + timer_set_period(IRSND_TICK_TIMER, timer_internal_clock_get(IRSND_TICK_TIMER) / F_INTERRUPTS - 1); /* Enable timer update interrupt */ - timer_enable_irq(IRSND_TICK_TIMER, TIM_DIER_UIE); - /* Counter enable. */ - timer_enable_counter(IRSND_TICK_TIMER); + timer_enable_irq(IRSND_TICK_TIMER, TIM_DIER_UIE); + /* Counter enable. */ + timer_enable_counter(IRSND_TICK_TIMER); #else /* Manually */ @@ -198,7 +199,7 @@ void IRSND_TICK_TIMER_ISR(void) debug_led_on(); /* Clear update interrupt flag. */ -#if USE_OPENCM3_API /* Using API functions: */ +#if USE_OPENCM3_API /* Using API functions: */ timer_clear_flag(IRSND_TICK_TIMER, TIM_SR_UIF); #else IRSND_TICK_TIMER_SR = ~TIM_SR_UIF; @@ -225,25 +226,21 @@ main (void) irsnd_init(); // initialize irsnd irsnd_tick_timer_init(); // initialize timer - ts = get_timer(0); - while (get_timer(ts) < 200) - ; - for (;;) { irmp_data.protocol = IRMP_NEC_PROTOCOL; // use NEC protocol - irmp_data.address = 0x4eb1; // set address to 0x00FF - irmp_data.command = 0x001e; // set command to 0x0001 + irmp_data.address = 0x4eb1; // Marantz RMC-12 + irmp_data.command = 0x001e; // SYSTEM 1 POWER irmp_data.flags = 0; // don't repeat frame ts = get_timer(0); led_on(); irsnd_send_data (&irmp_data, TRUE); // send frame, wait for completion - while (irsnd_is_busy()) - ; + while (irsnd_is_busy()) // wait till frame is + ; // completely sent led_off(); - while (get_timer(ts) < 2000) + while (get_timer(ts) < 1000) ; } }