OPN系FM音源チップを制御します

OPN3L(YMF288-M)を制御します。

OPNA(YM2608)やOPN(YM2203)にも使用可能だと思われますがテストしていません。

OPNの場合は拡張FM部を正しく指定してください。

ADPCM系はテストしていません。

読出しも未実装です。コメントアウトしてありますが確認とれていません。

このプログラムは YMF288変換基板+Arduinoで簡易S98プレーヤを作る(その1)(http://d.hatena.ne.jp/m_yanase/20130901/1378020818) を参考にしています。

Files at this revision

API Documentation at this revision

Comitter:
netwing
Date:
Wed Jan 13 15:26:27 2016 +0000
Parent:
1:df099d954a8f
Commit message:
WR RD???

Changed in this revision

FMOPN.cpp Show annotated file Show diff for this revision Revisions of this file
FMOPN.h Show annotated file Show diff for this revision Revisions of this file
diff -r df099d954a8f -r ea441ce9e405 FMOPN.cpp
--- a/FMOPN.cpp	Tue Jan 12 07:38:22 2016 +0000
+++ b/FMOPN.cpp	Wed Jan 13 15:26:27 2016 +0000
@@ -1,7 +1,7 @@
 #include "mbed.h"
 #include "FMOPN.h"
 #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
-OPN3L::OPN3L(
+FMOPN::FMOPN(
     PinName _D0,
     PinName _D1,
     PinName _D2,
@@ -13,13 +13,15 @@
     PinName RST,
     PinName A0,
     PinName A1,
-    PinName CS
-) : _BIT0(_D0), _BIT1(_D1), _BIT2(_D2), _BIT3(_D3), _BIT4(_D4), _BIT5(_D5), _BIT6(_D6), _BIT7(_D7), _RST(RST), _A0(A0), _A1(A1), _CS(CS)
+    PinName CS,
+    PinName WR,
+    PinName RD
+) : _BUS(_D0,_D1,_D2,_D3,_D4,_D5,_D6,_D7), _RST(RST), _A0(A0), _A1(A1), _CS(CS), _WR(WR), _RD(RD)
 {
 }
 
 // Reset
-void OPN3L::reset()
+void FMOPN::reset()
 {
     _RST = 0;
     wait_us(100);
@@ -29,7 +31,7 @@
 
 
 // Register Write
-void OPN3L::reg_write(unsigned char ifadr, unsigned char adr, unsigned char dat)
+void FMOPN::reg_write(unsigned char ifadr, unsigned char adr, unsigned char dat)
 {
     law_write(ifadr, adr, dat);
     switch (adr) {     // データライト後のWait
@@ -46,22 +48,38 @@
         }
     }
 }
-
+////Read
+//unsigned char FMOPN::reg_read(unsigned char ifadr, unsigned char adr)
+//{   
+//    DigitalOut LED(LED1,1);
+//    _BUS.output();
+//    _WR = 0;
+//    _RD = 1;
+//    adr_write(ifadr,adr);
+//    _BUS.input();
+//    _WR = 1;
+//    _RD = 0;
+//    unsigned char dar=dat_read();
+//    return dar;
+//}
 
 //Write
-void OPN3L::law_write(unsigned char ifadr, unsigned char adr, unsigned char dat)
+void FMOPN::law_write(unsigned char ifadr, unsigned char adr, unsigned char dat)
 {   
+    _BUS.output();
+    _WR = 0;
+    _RD = 1;
     adr_write(ifadr,adr);
     dat_write(dat);
 
 }
 
 //Write Address
-void OPN3L::adr_write(unsigned char ifadr, unsigned char adr)
+void FMOPN::adr_write(unsigned char ifadr, unsigned char adr)
 {
     _A0 = 0;     // Address Bus set
     _A1 =  bitRead(ifadr, 0);
-    write_data(adr);         // Address set
+    _BUS = adr;         // Address set
     _CS = 0;
     wait_us(1);     //  min: 200ns wait
     _CS = 1;
@@ -69,24 +87,20 @@
 }
 
 //Write Data
-void OPN3L::dat_write(unsigned char dat)
+void FMOPN::dat_write(unsigned char dat)
 {
     _A0 = 1;     // Address Bus set
-    write_data(dat);         // Data set
+    _BUS = dat;         // Data set
     _CS = 0;
     wait_us(1);     //  min: 200ns wait
     _CS = 1;
 }
-
-//Operated signal line
-void OPN3L::write_data(unsigned char dat)
-{
-    _BIT0 = bitRead(dat, 0);
-    _BIT1 = bitRead(dat, 1);
-    _BIT2 = bitRead(dat, 2);
-    _BIT3 = bitRead(dat, 3);
-    _BIT4 = bitRead(dat, 4);
-    _BIT5 = bitRead(dat, 5);
-    _BIT6 = bitRead(dat, 6);
-    _BIT7 = bitRead(dat, 7);
-}
\ No newline at end of file
+////Read Data
+//unsigned char FMOPN::dat_read()
+//{
+//    _A0 = 1;     // Address Bus set
+//    _CS = 0;
+//    unsigned char d=_BUS;
+//    _CS = 1;
+//    return d;
+//}
diff -r df099d954a8f -r ea441ce9e405 FMOPN.h
--- a/FMOPN.h	Tue Jan 12 07:38:22 2016 +0000
+++ b/FMOPN.h	Wed Jan 13 15:26:27 2016 +0000
@@ -9,13 +9,13 @@
 
 
 #include "mbed.h"
-#ifndef __OPN3L__
-#define __OPN3L__
-class OPN3L
+#ifndef __FMOPN__
+#define __FMOPN__
+class FMOPN
 {
 public:
-    // D0 - 7 RST A0 A1 CS
-    OPN3L(
+    // D0 - 7 RST A0 A1 CS WR RD
+    FMOPN(
         PinName _D0,
         PinName _D1,
         PinName _D2,
@@ -27,32 +27,35 @@
         PinName RST,
         PinName A0,
         PinName A1,
-        PinName CS
+        PinName CS,
+        PinName WR,
+        PinName RD
     );
 
     // Reset
     void reset();
 
     // Write
+    // ifadr 0x00 A1 = 0
+    // ifadr 0x01 A1 = 1
+    // adr Address
+    // dat Data
     void reg_write(unsigned char ifadr, unsigned char adr, unsigned char dat);
+//    unsigned char reg_read(unsigned char ifadr, unsigned char adr);
+    
     void adr_write(unsigned char ifadr, unsigned char adr);
     void dat_write(unsigned char dat);
+//    unsigned char dat_read();
 
 private:
-    DigitalOut _BIT0;
-    DigitalOut _BIT1;
-    DigitalOut _BIT2;
-    DigitalOut _BIT3;
-    DigitalOut _BIT4;
-    DigitalOut _BIT5;
-    DigitalOut _BIT6;
-    DigitalOut _BIT7;
+
+    BusInOut _BUS;
     DigitalOut _RST;
     DigitalOut _A0;
     DigitalOut _A1;
     DigitalOut _CS;
-
-    void write_data(unsigned char dat);
+    DigitalOut _WR;
+    DigitalOut _RD;
 
     void law_write(unsigned char ifadr, unsigned char adr, unsigned char dat);