OSDN Git Service

Added rotary encoder module.
authorShinichiro Nakamura <shinta.main.jp@gmail.com>
Fri, 24 Aug 2012 20:16:46 +0000 (05:16 +0900)
committerShinichiro Nakamura <shinta.main.jp@gmail.com>
Fri, 24 Aug 2012 20:16:46 +0000 (05:16 +0900)
firm/bare_metal/Makefile
firm/bare_metal/main.c
firm/bare_metal/rotenc.c [new file with mode: 0644]
firm/bare_metal/rotenc.h [new file with mode: 0644]
firm/bare_metal/uzume.c

index 3f23013..2f5287b 100644 (file)
@@ -6,7 +6,7 @@ PROJECT = bluetank
 #
 # Source files and search directories
 #
-CSRC   += lcd.c led.c
+CSRC   += lcd.c led.c rotenc.c
 CSRC   += mmc.c pff.c
 CSRC   += twi.c uart.c
 CSRC   += ssm2603.c at24c.c
index dfbbbd9..1cf263c 100644 (file)
 #include <stddef.h>
 #include "uzume.h"
 #include "lcd.h"
+#include "led.h"
 #include "effect.h"
+#include "rotenc.h"
+
+typedef struct {
+    uint8_t swstat;
+    uint8_t effect;
+} work_t;
 
 static void system_default(UZUME *p)
 {
-    uint32_t ivl = UZUME_VOLUME_INPUT(p).left >> 29;
-    uint32_t ivr = UZUME_VOLUME_INPUT(p).right >> 29;
-    uint32_t ovl = UZUME_VOLUME_OUTPUT(p).left >> 29;
-    uint32_t ovr = UZUME_VOLUME_OUTPUT(p).right >> 29;
+    work_t *w = (work_t *)UZUME_USER_DATA(p);
+
     lcd_goto(0, 0);
-    lcd_putc(0x08 + ivl);
-    lcd_putc(0x08 + ivr);
-    lcd_putc(0x08 + ovl);
-    lcd_putc(0x08 + ovr);
+    lcd_putc(0x08 + UZUME_VOLUME_INPUT(p).left >> 29);
+    lcd_putc(0x08 + UZUME_VOLUME_INPUT(p).right >> 29);
+    lcd_putc(0x08 + UZUME_VOLUME_OUTPUT(p).left >> 29);
+    lcd_putc(0x08 + UZUME_VOLUME_OUTPUT(p).right >> 29);
+
+    w->swstat = (w->swstat << 1) | rotenc_swstat();
+    if (w->swstat == 0x0F) {
+        w->effect = !w->effect;
+        if (w->effect) {
+            uzume_set_effect(p, effect_karaoke);
+            led_write(LedTargetR, 0);
+            led_write(LedTargetG, 1);
+        } else {
+            uzume_set_effect(p, effect_through);
+            led_write(LedTargetR, 1);
+            led_write(LedTargetG, 0);
+        }
+    }
 }
 
 int main(void)
 {
     UZUME u;
+    work_t w;
+
+    w.swstat = 0;
+    w.effect = 0;
 
-    uzume_init(&u, NULL);
+    uzume_init(&u, &w);
     uzume_set_effect(&u, effect_karaoke);
     uzume_set_system(&u, system_default);
     uzume_execute(&u);
diff --git a/firm/bare_metal/rotenc.c b/firm/bare_metal/rotenc.c
new file mode 100644 (file)
index 0000000..c8f730e
--- /dev/null
@@ -0,0 +1,26 @@
+
+#include <cdefBF592-A.h>
+#include "rotenc.h"
+
+/*
+ * SW : PF10
+ */
+
+#define INIT_PORT() \
+    do { \
+        *pPORTF_FER &= ~(PF10); \
+        *pPORTFIO_DIR &= ~(PF10); \
+        *pPORTFIO_INEN |= (PF10); \
+    } while (0)
+#define SW_STAT()   (((*pPORTFIO) & (1 << 10)) ? 0 : 1)
+
+void rotenc_init(void)
+{
+    INIT_PORT();
+}
+
+int rotenc_swstat(void)
+{
+    return SW_STAT();
+}
+
diff --git a/firm/bare_metal/rotenc.h b/firm/bare_metal/rotenc.h
new file mode 100644 (file)
index 0000000..4ee00d6
--- /dev/null
@@ -0,0 +1,9 @@
+
+#ifndef ROTENC_H
+#define ROTENC_H
+
+void rotenc_init(void);
+int rotenc_swstat(void);
+
+#endif
+
index 66a7c7f..a5c77b3 100644 (file)
@@ -46,6 +46,7 @@
 #include "uzume.h"
 #include "mmc.h"
 #include "uart.h"
+#include "rotenc.h"
 
 #define SCLOCK_HZ           (100000000) /**< システムクロック(100MHz) */
 #define DMA_SAMPLE_SIZE     (256)       /**< 1回のサンプルサイズ */
@@ -107,8 +108,6 @@ static void vdsp_register_handler(interrupt_kind kind, ex_handler_fn_gcc fn)
 
 void uzume_init(UZUME *p, void *user_data)
 {
-    uint8_t c;
-    bool sdc_detected;
     FATFS fatfs;
 #if 0
     DIR dir;
@@ -130,8 +129,6 @@ void uzume_init(UZUME *p, void *user_data)
      * LEDを初期化する。
      */
     led_init();
-    led_write(LedTargetR, 1);
-    led_write(LedTargetG, 0);
 
     /*
      * LCDを初期化する。
@@ -141,7 +138,7 @@ void uzume_init(UZUME *p, void *user_data)
     lcd_goto(0, 0);
     lcd_puts("BlueTank");
     lcd_goto(0, 1);
-    lcd_puts("Init....");
+    lcd_puts(" UZUME! ");
 
     /*
      * オーディオコーデックを初期化する。
@@ -158,11 +155,6 @@ void uzume_init(UZUME *p, void *user_data)
      * SDカードをマウントする。
      */
     pf_mount(&fatfs);
-    if (MMC_DETECT()) {
-        sdc_detected = true;
-    } else {
-        sdc_detected = false;
-    }
 
     /*
      * バッファをクリアする。
@@ -234,18 +226,6 @@ void uzume_init(UZUME *p, void *user_data)
     ssync();
 
     /*
-     * 初期化の完了をユーザに通知する。
-     */
-    led_write(LedTargetR, 0);
-    led_write(LedTargetG, 1);
-    lcd_goto(0, 1);
-    if (sdc_detected) {
-        lcd_puts("SDC: Yes");
-    } else {
-        lcd_puts("SDC: No ");
-    }
-
-    /*
      * ミュートを解除する。
      */
     ssm2603_mute(false);
@@ -254,6 +234,8 @@ void uzume_init(UZUME *p, void *user_data)
      * AT24C test...
      */
     at24c_init();
+
+    rotenc_init();
 }
 
 void uzume_set_effect(UZUME *p, UZUME_EFFECT_FUNC effect)
@@ -314,10 +296,6 @@ void uzume_execute(UZUME *p)
                         sport_buffer_tx[bufidx_dma_done],
                         DMA_SAMPLE_SIZE);
             }
-            /*
-             *
-             */
-            led_write(LedTargetR, 1);
         }
         if (p->system != NULL) {
             p->system(p);