OSDN Git Service

[General] Initial files.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 10 Jun 2013 19:57:02 +0000 (04:57 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 10 Jun 2013 19:57:02 +0000 (04:57 +0900)
Makefile [new file with mode: 0644]
i2c_io.c [new file with mode: 0644]
iodef.h [new file with mode: 0644]
main.c [new file with mode: 0644]
ui.c [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..05a3fb1
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,108 @@
+#
+#  There exist several targets which are by default empty and which can be 
+#  used for execution of your targets. These targets are usually executed 
+#  before and after some main targets. They are: 
+#
+#     .build-pre:              called before 'build' target
+#     .build-post:             called after 'build' target
+#     .clean-pre:              called before 'clean' target
+#     .clean-post:             called after 'clean' target
+#     .clobber-pre:            called before 'clobber' target
+#     .clobber-post:           called after 'clobber' target
+#     .all-pre:                called before 'all' target
+#     .all-post:               called after 'all' target
+#     .help-pre:               called before 'help' target
+#     .help-post:              called after 'help' target
+#
+#  Targets beginning with '.' are not intended to be called on their own.
+#
+#  Main targets can be executed directly, and they are:
+#  
+#     build                    build a specific configuration
+#     clean                    remove built files from a configuration
+#     clobber                  remove all built files
+#     all                      build all configurations
+#     help                     print help mesage
+#  
+#  Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
+#  .help-impl are implemented in nbproject/makefile-impl.mk.
+#
+#  Available make variables:
+#
+#     CND_BASEDIR                base directory for relative paths
+#     CND_DISTDIR                default top distribution directory (build artifacts)
+#     CND_BUILDDIR               default top build directory (object files, ...)
+#     CONF                       name of current configuration
+#     CND_ARTIFACT_DIR_${CONF}   directory of build artifact (current configuration)
+#     CND_ARTIFACT_NAME_${CONF}  name of build artifact (current configuration)
+#     CND_ARTIFACT_PATH_${CONF}  path to build artifact (current configuration)
+#     CND_PACKAGE_DIR_${CONF}    directory of package (current configuration)
+#     CND_PACKAGE_NAME_${CONF}   name of package (current configuration)
+#     CND_PACKAGE_PATH_${CONF}   path to package (current configuration)
+#
+# NOCDDL
+
+
+# Environment 
+MKDIR=mkdir
+CP=cp
+CCADMIN=CCadmin
+RANLIB=ranlib
+
+
+# build
+build: .build-post
+
+.build-pre:
+# Add your pre 'build' code here...
+
+.build-post: .build-impl
+# Add your post 'build' code here...
+
+
+# clean
+clean: .clean-post
+
+.clean-pre:
+# Add your pre 'clean' code here...
+
+.clean-post: .clean-impl
+# Add your post 'clean' code here...
+
+
+# clobber
+clobber: .clobber-post
+
+.clobber-pre:
+# Add your pre 'clobber' code here...
+
+.clobber-post: .clobber-impl
+# Add your post 'clobber' code here...
+
+
+# all
+all: .all-post
+
+.all-pre:
+# Add your pre 'all' code here...
+
+.all-post: .all-impl
+# Add your post 'all' code here...
+
+
+# help
+help: .help-post
+
+.help-pre:
+# Add your pre 'help' code here...
+
+.help-post: .help-impl
+# Add your post 'help' code here...
+
+
+
+# include project implementation makefile
+include nbproject/Makefile-impl.mk
+
+# include project make variables
+include nbproject/Makefile-variables.mk
diff --git a/i2c_io.c b/i2c_io.c
new file mode 100644 (file)
index 0000000..ecb0767
--- /dev/null
+++ b/i2c_io.c
@@ -0,0 +1,10 @@
+/*
+ * OpenI2CRADIO
+ * I2C Handler
+ * (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
+ * License: GPL2
+ */
+
+#include <sdcc-lib.h>
+#include <pic18fregs.h> /* ONLY FOR PIC18x */
+
diff --git a/iodef.h b/iodef.h
new file mode 100644 (file)
index 0000000..fedc16c
--- /dev/null
+++ b/iodef.h
@@ -0,0 +1,126 @@
+/*
+ * OpenI2CRADIO
+ * I/O Port defines.
+ * (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
+ * License: GPL2
+ */
+
+#ifndef IODEF_H
+#define        IODEF_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*
+ * MAP OF IOPORT
+ * PORTA/B/C USED.
+ * PORTA: RA2-RA5 : READ
+ *        RA1 : SLOT D(OUT)
+ *        RA0 : ADC(IN)
+ *        RA6-RA7 : CLOCK
+ * PORTB: RB4-RB5 : RESERVED
+ *        RB6-RB7 : FOR ICSP
+ *        RB3 : DEL / BAND
+ *        RB2 : FUNC
+ *        RB1 : Light
+ *        RB0 : Light Out
+ * PORTC  RC0 : LED
+ *        RC1 : SLOT A
+ *        RC2 : SLOT B
+ *        RC5 : SLOT C
+ *        RC3-RC4 : SCL/SDA
+ *        RC6-RC7 : USART
+ */
+
+#define TRIS_A_VAL 0b11111101
+#define AN_A_VAL 0b00000001
+#define TRIS_B_VAL 0b11111110
+#define AN_B_VAL 0b00000000
+#define TRIS_C_VAL_O 0b11000000 /* FOR I2C-WRITE */
+#define TRIS_C_VAL_I 0b11011000 /* FOR I2C-WRITE */
+#define AN_C_VAL 0b00000000
+
+typedef  union {
+    struct {
+    unsigned BIT0A:1;
+    unsigned BIT1A:1;
+    unsigned BIT2A:1;
+    unsigned BIT3A:1;
+
+    unsigned BIT0B:1;
+    unsigned BIT1B:1;
+    unsigned BIT2B:1;
+    unsigned BIT3B:1;
+
+    unsigned BIT0C:1;
+    unsigned BIT1C:1;
+    unsigned BIT2C:1;
+    unsigned BIT3C:1;
+
+    unsigned BIT0D:1;
+    unsigned BIT1D:1;
+    unsigned BIT2D:1;
+    unsigned BIT3D:1;
+
+    /*
+     * special keys
+     */
+    unsigned BIT0F:1;
+    unsigned BIT1F:1;
+    unsigned BIT2F:1;
+    unsigned BIT3F:1;
+    unsigned :1;
+    unsigned :1;
+    unsigned :1;
+    unsigned :1;
+    };
+    unsigned char byte[3];
+} keyin_defs;
+
+enum {
+    charcode_null = 0,
+    charcode_1,
+    charcode_2,
+    charcode_3,
+    charcode_4,
+    charcode_5,
+    charcode_6,
+    charcode_7,
+    charcode_8,
+    charcode_9,
+    charcode_a,
+    charcode_b,
+    charcode_c,
+    charcode_d,
+    charcode_e,
+    charcode_f,
+    charcode_0,
+    charcode_s0,
+    charcode_s1,
+    charcode_s2,
+    charcode_s3,
+};
+
+extern keyin_defs keyin_old[2];
+extern keyin_defs keyin_now;
+extern char keyin_fifo[16];
+extern char keyin_nowp;
+extern char keyin_counter;
+
+extern unsigned char readkey_compare(void);
+extern void readkey_io(void);
+extern void push_keyinfifo(char b);
+extern char pop_keyinfifo(void);
+extern void keyin_ioinit(void);
+extern void keyin_init(void);
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* IODEF_H */
+
diff --git a/main.c b/main.c
new file mode 100644 (file)
index 0000000..5397bd0
--- /dev/null
+++ b/main.c
@@ -0,0 +1,41 @@
+/*
+ * OpenI2CRADIO
+ * Config & Main routine.
+ * (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
+ * License: GPL2
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sdcc-lib.h>
+#include <pic18fregs.h> /* ONLY FOR PIC18x */
+
+#include "iodef.h"
+
+/*
+ * Config words.
+ */
+__at(__CONFIG1H) _config1h = _FOSC_INTIO67_1H;
+__at(__CONFIG2L) _config2l = _BORV_190_2L & _BOREN_ON_2L & _PWRTEN_ON_2L;
+__at(__CONFIG2H) _config2h = _WDTEN_ON_2H & _WDTPS_32768_2H;
+__at(__CONFIG3H) _config3h = _PBADEN_OFF_3H & _MCLRE_EXTMCLR_3H;
+__at(__CONFIG4L) _config4l = _STVREN_ON_4L & _LVP_OFF_4L & _XINST_ON_4L & _DEBUG_ON_4L;
+__at(__CONFIG5L) _config5l = _CP0_OFF_5L & _CP1_OFF_5L;
+__at(__CONFIG5H) _config5h = _CPB_OFF_5H & _CPD_OFF_5H;
+__at(__CONFIG6L) _config6l = _WRT0_OFF_6L & _WRT1_OFF_6L;
+__at(__CONFIG6H) _config6h = _WRTD_OFF_6H & _WRTB_OFF_6H & _WRTC_OFF_6H;
+__at(__CONFIG7L) _config7l = _EBTR0_OFF_7L & _EBTR1_OFF_7L;
+__at(__CONFIG7H) _config7h = _EBTRB_OFF_7H;
+
+
+/*
+ * 
+ */
+int main(void) {
+
+    keyin_init();
+    keyin_ioinit();
+    
+
+}
+
diff --git a/ui.c b/ui.c
new file mode 100644 (file)
index 0000000..a1b3547
--- /dev/null
+++ b/ui.c
@@ -0,0 +1,199 @@
+/*
+ * OpenI2CRADIO
+ * UI Handler
+ * (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
+ * License: GPL2
+ */
+
+#include <sdcc-lib.h>
+#include <pic18fregs.h> /* ONLY FOR PIC18x */
+
+#include "iodef.h"
+
+keyin_defs keyin_old[2];
+keyin_defs keyin_now;
+char keyin_fifo[16];
+char keyin_nowp;
+char keyin_readp;
+char keyin_counter;
+
+void keyin_init(void)
+{
+    char i;
+    /* Initialize vars*/
+    for(i = 0; i < 3; i++) {
+        keyin_old[0].byte[i] = 0x00;
+        keyin_old[1].byte[i] = 0x00;
+        keyin_now.byte[i] = 0x00;
+    }
+    for(i = 0; i < 16; i++) keyin_fifo[i] = 0x00;
+    keyin_nowp = 0;
+    keyin_readp = 0;
+    keyin_counter = 0;
+
+}
+
+void keyin_ioinit(void)
+{
+    /* Initialize IOPORTS*/
+    PORTA = 0x00;
+    LATA = 0x00;
+    ANSELA = AN_A_VAL;
+    TRISA = TRIS_A_VAL;
+
+    PORTB = 0x00;
+    LATB = 0x00;
+    ANSELB = AN_B_VAL;
+    TRISB = TRIS_B_VAL;
+
+    PORTC = 0x00;
+    LATC = 0x00;
+    ANSELC = AN_C_VAL;
+    TRISC = TRIS_C_VAL_O;
+}
+
+/*
+ * Push to keyin fifo; not used atomic-writing.
+ */
+void push_keyinfifo(char b)
+{
+    keyin_nowp++;
+    if((keyin_nowp > 15) || (keyin_nowp < 0))keyin_nowp = 0;
+    keyin_fifo[keyin_nowp] = b;
+    keyin_counter++;
+    if(keyin_counter > 16) keyin_counter = 16;
+}
+
+/*
+ * Pop from keyin fifo; not used atomic-reading.
+ */
+char pop_keyinfifo(void)
+{
+    char c;
+    if(keyin_counter <= 0) {
+        keyin_counter = 0;
+        return charcode_null ;
+    }
+    if(keyin_readp > 15) keyin_readp = 15;
+    c = keyin_fifo[keyin_readp];
+    keyin_readp++;
+    if(keyin_readp > 15) keyin_readp = 0;
+    keyin_counter--;
+    if(keyin_counter < 0)keyin_counter = 0;
+    return c;
+}
+
+
+/*
+ * Read IOPORTS for KEY.
+ */
+void readkey_io(void)
+{
+    char i;
+    unsigned char portvar;
+    unsigned char latchvar;
+    unsigned char high;
+    unsigned char low;
+    if(keyin_counter > 16) keyin_counter = 0;
+    for(i = 0; i < 3; i++){
+        keyin_old[1].byte[i] = keyin_old[0].byte[i];
+        keyin_old[0].byte[i] = keyin_now.byte[i];
+        keyin_now.byte[i] = 0x00;
+     }
+     /* SCANLINE A*/
+    latchvar = LATA | 0x02;
+    LATA = latchvar;
+    portvar = PORTA;
+    low = (portvar & 0x3c) >>2;
+    latchvar = LATA & 0xfd;
+    LATA = latchvar;
+    /* SCANLINE B*/
+    latchvar = LATB | 0x02;
+    LATB = latchvar;
+    portvar = PORTA;
+    high = (portvar & 0x3c) >>2;
+    latchvar = LATB & 0xfd;
+    LATB = latchvar;
+    /* Pos */
+    keyin_now.byte[0] = (low << 4) | high;
+
+    /* SCANLINE C*/
+    latchvar = LATB | 0x04;
+    LATA = latchvar;
+    portvar = PORTA;
+    low = (portvar & 0x3c) >>2;
+    latchvar = LATB & 0xfb;
+    LATA = latchvar;
+    /* SCANLINE D*/
+    latchvar = LATB | 0x20;
+    LATB = latchvar;
+    portvar = PORTA;
+    high = (portvar & 0x3c) >>2;
+    latchvar = LATB & 0xdf;
+    LATB = latchvar;
+    /* Pos */
+    keyin_now.byte[1] = (low << 4) | high;
+
+    /* Special KEYS */
+    keyin_now.BIT0F = PORTBbits.RB1;
+    keyin_now.BIT1F = PORTBbits.RB2;
+    keyin_now.BIT2F = PORTBbits.RB3;
+    keyin_now.BIT3F = 0; // Reserve
+}
+
+unsigned char readkey_compare(void)
+{
+    char b;
+    char c;
+    char d;
+    char e;
+    unsigned char shift;
+    unsigned char f;
+    f = 0;
+    e = 0;
+    for(d = 0; d < 3; d++) {
+        shift = 0x01;
+        for(b = 0; b < 8; b++){
+            c = 0;
+            if((keyin_now.byte[c] & shift) != 0) c++;
+            if((keyin_old[0].byte[c] & shift) != 0) c++;
+            if((keyin_old[1].byte[c] & shift) != 0) c++;
+            if(c >= 2) {
+            /*
+             * Clear older-inputs on .
+             */
+                f |= 1;
+                keyin_old[0].byte[c] &= ~shift;
+                keyin_old[1].byte[c] &= ~shift;
+                keyin_now.byte[c] &= ~shift;
+                if(e == 0) {
+                    push_keyinfifo(charcode_0);
+                } else if(e <= 15) {
+                    push_keyinfifo(b);
+                } else if(e < 20) {
+                    push_keyinfifo(e + 1);
+                }
+            }
+            shift <<= 1;
+            e++;
+        }
+    }
+    /**/
+    return f;
+}
+
+/*
+ * Notes:
+ * Initialize sequence:
+ * keyin_init();
+ * keyin_ioinit();
+ * 
+ * Read-key-sequence:
+ * In interrupt/unsleep hook(call per Nms):
+ * readkey_io();
+ * readkey_compare();
+ *
+ * In application handler:
+ * c = pop_keyinfifo();
+ * if(c != 0) do(c);
+ */
\ No newline at end of file