OSDN Git Service

Updated the rotary encoder module.
authorShinichiro Nakamura <shinta.main.jp@gmail.com>
Sat, 25 Aug 2012 10:50:20 +0000 (19:50 +0900)
committerShinichiro Nakamura <shinta.main.jp@gmail.com>
Sat, 25 Aug 2012 10:50:20 +0000 (19:50 +0900)
firm/bare_metal/main.c
firm/bare_metal/rotenc.c
firm/bare_metal/rotenc.h
firm/bare_metal/uzume.c
ref/ADSP-BF592.pdf [new file with mode: 0644]
ref/ADSP-BF59x_hwr_rev0.1.pdf [new file with mode: 0644]

index 55fbdc9..bb90e4c 100644 (file)
 #include "rotenc.h"
 
 typedef struct {
-    uint8_t swstat;
+    UZUME uzume;
     uint8_t effect;
+    int8_t locate_target;
+    int8_t locate_current;
 } work_t;
 
-static void system_default(UZUME *p)
+static void rotenc_callback(RotencAction action, void *extobj)
 {
-    work_t *w = (work_t *)UZUME_USER_DATA(p);
-
-    lcd_goto(0, 0);
-    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);
-    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) {
+    work_t *w = (work_t *)extobj;
+    if (RotencActionPush == action) {
         w->effect = !w->effect;
         if (w->effect) {
-            uzume_set_effect(p, effect_karaoke);
+            uzume_set_effect(&(w->uzume), effect_karaoke);
             led_write(LedTargetR, 0);
             led_write(LedTargetG, 1);
+
         } else {
-            uzume_set_effect(p, effect_through);
+            uzume_set_effect(&(w->uzume), effect_through);
             led_write(LedTargetR, 1);
             led_write(LedTargetG, 0);
         }
     }
+    if (RotencActionLeft == action) {
+        w->locate_target-=8;
+        if (w->locate_target < 0) {
+            w->locate_target = 0;
+        }
+    }
+    if (RotencActionRight == action) {
+        w->locate_target+=8;
+        if (32 < w->locate_target) {
+            w->locate_target = 32;
+        }
+    }
+}
+
+static void system_default(UZUME *p)
+{
+    work_t *w = (work_t *)UZUME_USER_DATA(p);
+
+    lcd_goto(0, 0);
+    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));
+    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));
+
+#define SCROLL_SPEED    (16)
+    static uint8_t divcnt = 0;
+    if (((divcnt++) % SCROLL_SPEED) == 0) {
+        if (w->locate_current < w->locate_target) {
+            lcd_display_shift(Left);
+            w->locate_current++;
+        }
+        if (w->locate_target < w->locate_current) {
+            lcd_display_shift(Right);
+            w->locate_current--;
+        }
+    }
 }
 
 int main(void)
 {
-    UZUME u;
     work_t w;
 
-    w.swstat = 0;
     w.effect = 0;
+    w.locate_target = 0;
+    w.locate_current = 0;
 
-    uzume_init(&u, &w);
-    uzume_set_effect(&u, effect_through);
-    uzume_set_system(&u, system_default);
+    uzume_init(&w.uzume, &w);
+    uzume_set_effect(&w.uzume, effect_through);
+    uzume_set_system(&w.uzume, system_default);
     led_write(LedTargetR, 1);
     led_write(LedTargetG, 0);
-    uzume_execute(&u);
+    rotenc_init(rotenc_callback, &w);
+    uzume_execute(&w.uzume);
 
     return 0;
 }
index c8f730e..627daf3 100644 (file)
+/**
+ * @file rotenc.c
+ * @author Copyright(C) 2012 Shinichiro Nakamura
+ * @brief BlueTank ACB-BF592 Application Sample Codes.
+ */
 
+/*
+ * ===============================================================
+ *  BlueTank
+ * ===============================================================
+ * Copyright (c) 2012 Shinichiro Nakamura
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ * ===============================================================
+ */
+
+#include <stddef.h>
 #include <cdefBF592-A.h>
+#include <builtins.h>
+#include <sys/exception.h>
 #include "rotenc.h"
 
 /*
+ * PA : PF6
+ * PB : PF7
  * SW : PF10
  */
 
+/* \e$B%7%9%F%`%/%m%C%/\e(B(100MHz) */
+#define SCLOCK_HZ   (100000000)
+
 #define INIT_PORT() \
     do { \
-        *pPORTF_FER &= ~(PF10); \
-        *pPORTFIO_DIR &= ~(PF10); \
-        *pPORTFIO_INEN |= (PF10); \
+        *pPORTF_FER     &= ~(PF6 | PF7 | PF10); \
+        *pPORTFIO_DIR   &= ~(PF6 | PF7 | PF10); \
+        *pPORTFIO_INEN  |=  (PF6 | PF7 | PF10); \
     } while (0)
-#define SW_STAT()   (((*pPORTFIO) & (1 << 10)) ? 0 : 1)
+#define PA_STAT()   (((*pPORTFIO) & (1 <<  6)) ? 1 : 0)
+#define PB_STAT()   (((*pPORTFIO) & (1 <<  7)) ? 1 : 0)
+#define SW_STAT()   (((*pPORTFIO) & (1 << 10)) ? 1 : 0)
 
-void rotenc_init(void)
+ROTENC_CALLBACK callback = NULL;
+void *user_obj = NULL;
+
+typedef __attribute__((interrupt_handler)) void (*ex_handler_fn_gcc)(void);
+
+static __attribute__((interrupt_handler)) void rotenc_isr(void)
 {
-    INIT_PORT();
+    /* \e$B3d$j9~$_%9%F!<%?%9$N99?7\e(B */
+    *pTIMER_STATUS = TIMIL0;
+    ssync();
+
+    static uint8_t swstat = 0;
+    static const int dir[] = { 0,1,-1,0,-1,0,0,1,1,0,0,-1,0,-1,1,0 };
+    static int index;
+    int n;
+
+    index = (index << 2) + (((PA_STAT() << 1) | (PB_STAT() << 0)) & 3);
+    n = dir[index & 15];
+    if (n) {
+        if (n < 0) {
+            callback(RotencActionLeft, user_obj);
+        }
+        if (0 < n) {
+            callback(RotencActionRight, user_obj);
+        }
+    }
+    swstat = (swstat << 1) | SW_STAT();
+    if (swstat == 0x0F) {
+        callback(RotencActionPush, user_obj);
+    }
 }
 
-int rotenc_swstat(void)
+/* Visual DSP++\e$B$N\e(Bregister_handler\e$B4X?t<BAu\e(B */
+static void s_bfin_register_handler(interrupt_kind kind, ex_handler_fn_gcc fn)
 {
-    return SW_STAT();
+    uint32_t l_mask;
+
+    if((ik_emulation > kind) || (kind > ik_ivg15)) return;
+
+    *((ex_handler_fn_gcc*)&(((uint32_t*)EVT0)[(int32_t)kind])) = fn;
+    l_mask  = cli();
+    l_mask |= 1u << (int32_t)kind;
+    sti(l_mask);
+}
+
+void rotenc_init(ROTENC_CALLBACK func, void *extobj)
+{
+    INIT_PORT();
+
+    callback = func;
+    user_obj = extobj;
+
+    /* \e$B3d$j9~$_%O%s%I%i$r\e(BIVG11\e$B$KEPO?\e(B */
+    s_bfin_register_handler(ik_ivg11, rotenc_isr);
+    *pSIC_IMASK |= IRQ_TIMER0;
+
+    /* GP\e$B%?%$%^\e(B0\e$B$N@_Dj\e(B */
+    /* 1ms\e$BC10L$K3d$j9~$_$,$+$+$k$h$&$K@_Dj\e(B */
+    *pTIMER0_CONFIG = OUT_DIS | IRQ_ENA | PERIOD_CNT | PWM_OUT;
+    *pTIMER0_PERIOD = SCLOCK_HZ / 1000;
+    *pTIMER0_WIDTH = 1;
+    *pTIMER_ENABLE = TIMEN0;
+    ssync();
 }
 
index 4ee00d6..bcdb5e7 100644 (file)
@@ -1,9 +1,51 @@
+/**
+ * @file rotenc.h
+ * @author Copyright(C) 2012 Shinichiro Nakamura
+ * @brief BlueTank ACB-BF592 Application Sample Codes.
+ */
+
+/*
+ * ===============================================================
+ *  BlueTank
+ * ===============================================================
+ * Copyright (c) 2012 Shinichiro Nakamura
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ * ===============================================================
+ */
 
 #ifndef ROTENC_H
 #define ROTENC_H
 
-void rotenc_init(void);
-int rotenc_swstat(void);
+typedef enum {
+    RotencActionNone,
+    RotencActionPush,
+    RotencActionLeft,
+    RotencActionRight,
+} RotencAction;
+
+typedef void (*ROTENC_CALLBACK)(RotencAction action, void *extobj);
+
+void rotenc_init(ROTENC_CALLBACK func, void *extobj);
 
 #endif
 
index a5c77b3..1cf358e 100644 (file)
@@ -46,7 +46,6 @@
 #include "uzume.h"
 #include "mmc.h"
 #include "uart.h"
-#include "rotenc.h"
 
 #define SCLOCK_HZ           (100000000) /**< システムクロック(100MHz) */
 #define DMA_SAMPLE_SIZE     (256)       /**< 1回のサンプルサイズ */
@@ -231,11 +230,9 @@ void uzume_init(UZUME *p, void *user_data)
     ssm2603_mute(false);
 
     /*
-     * AT24C test...
+     * AT24C initialize.
      */
     at24c_init();
-
-    rotenc_init();
 }
 
 void uzume_set_effect(UZUME *p, UZUME_EFFECT_FUNC effect)
@@ -277,6 +274,11 @@ void uzume_execute(UZUME *p)
     lcd_goto(0, 0);
     lcd_puts(lcdbuf);
 
+    lcd_puts("[MENU 1]");
+    lcd_puts("[MENU 2]");
+    lcd_puts("[MENU 3]");
+    lcd_puts("[MENU 4]");
+
     while (1) {
         asm("idle;");
         if (0 != data_ready) {
diff --git a/ref/ADSP-BF592.pdf b/ref/ADSP-BF592.pdf
new file mode 100644 (file)
index 0000000..c9e0a50
Binary files /dev/null and b/ref/ADSP-BF592.pdf differ
diff --git a/ref/ADSP-BF59x_hwr_rev0.1.pdf b/ref/ADSP-BF59x_hwr_rev0.1.pdf
new file mode 100644 (file)
index 0000000..2186724
Binary files /dev/null and b/ref/ADSP-BF59x_hwr_rev0.1.pdf differ