Sample Program for Marutsu-elec MAPLE-mini TypeA board(MARM02-BASE)

Dependencies:   LSM303DLHC RX8025 SDFileSystem TextLCD TouchSense mbed

マルツで販売している MAPLE-mini TypeA基板上のデバイス用のライブラリを集めてみました。
以下の点で不満が残っているので、今後改良する予定です。

  • RTCチップの INTA,INTBが結線されていますが、このライブラリには含まれていません。
  • タッチパッドは裏側を触ればOnになりますが、これが基板の仕様なのかどうか不明です。
  • 圧電ブザーはp20に結線されていて mbed1768ではp20はPWMが使えませんので、DigitalOut で使っています。

2016/06/11 9:54 LCDでアイコンの表示を付け加えました
2016/06/12 SDカードの CD1を利用するようにしました。加速度センサのライブラリを書き直して温度も取得できるようにしました。

Committer:
jk1lot
Date:
Sat Jun 11 00:41:33 2016 +0000
Revision:
3:aae83c4bd9a0
Parent:
1:707a0a314781
Child:
4:faf01cf17d60
added display ICON

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jk1lot 1:707a0a314781 1 /* Sample for MAPLE-mini TypeA board(marutsu-elec MARM02-BASE)
jk1lot 1:707a0a314781 2 * マルツの MAPLE-mini TypeA基板(型番MARM02-BASE)用の動作確認用のプログラムです。
jk1lot 3:aae83c4bd9a0 3 * mbed1768での動作を確認しています。
jk1lot 1:707a0a314781 4 */
jk1lot 1:707a0a314781 5
jk1lot 0:06047ad53505 6 #include "mbed.h"
jk1lot 1:707a0a314781 7 //液晶モジュール MI2CLCD-01 I2C(p28,p27)
jk1lot 0:06047ad53505 8 #include "TextLCD.h"
jk1lot 1:707a0a314781 9 //RTC RX-8025SA I2C(p28,p27) INTA-p25 INTB-p26
jk1lot 0:06047ad53505 10 #include "RX8025.h"
jk1lot 1:707a0a314781 11 //地磁気+加速度センサモジュール MLSM303DLHC I2C(p28,p27)
jk1lot 0:06047ad53505 12 #include "LSM303DLH.h"
jk1lot 1:707a0a314781 13 //microSD card slot SPI(P5,p6,p7,CS-p22 CD1-p29)
jk1lot 0:06047ad53505 14 #include "SDFileSystem.h"
jk1lot 1:707a0a314781 15 //基板に作り込みの静電式タッチパッド p15~18
jk1lot 0:06047ad53505 16 #include "TouchSense.h"
jk1lot 1:707a0a314781 17 //圧電スピーカ p20
jk1lot 1:707a0a314781 18 //TypeB,C基板接続用コネクタ UART(p9,p10) I2C(p28,p27)
jk1lot 1:707a0a314781 19
jk1lot 1:707a0a314781 20 DigitalOut myled(LED1);
jk1lot 0:06047ad53505 21
jk1lot 0:06047ad53505 22 I2C i2c(p28,p27); // SDA, SCL
jk1lot 0:06047ad53505 23 TextLCD_I2C_N lcd(&i2c, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3);
jk1lot 3:aae83c4bd9a0 24 // LCD icon test patterns
jk1lot 3:aae83c4bd9a0 25 const int MAXICONS=13;
jk1lot 3:aae83c4bd9a0 26 struct {
jk1lot 3:aae83c4bd9a0 27 int8_t address;
jk1lot 3:aae83c4bd9a0 28 int8_t data;
jk1lot 3:aae83c4bd9a0 29 } const icons[MAXICONS] = { {0x00,0x10},{0x02,0x10},{0x04,0x10},{0x06, 0x10},
jk1lot 3:aae83c4bd9a0 30 {0x07,0x10},{0x07,0x08},{0x09,0x10},{0x0b,0x10},
jk1lot 3:aae83c4bd9a0 31 {0x0d,0x1e},{0x0d,0x1a},{0x0d,0x12},{0x0d,0x02},
jk1lot 3:aae83c4bd9a0 32 {0x0f,0x10} };
jk1lot 0:06047ad53505 33 RX8025 rtc(i2c);
jk1lot 0:06047ad53505 34 LSM303DLH compass(p28, p27);
jk1lot 0:06047ad53505 35 SDFileSystem sd(p5, p6, p7, p22, "sd");
jk1lot 1:707a0a314781 36
jk1lot 1:707a0a314781 37 //基板の裏側に触らないと ONにならない
jk1lot 1:707a0a314781 38 //構造的にそういう仕様っぽいけど、どうなんだろ?
jk1lot 0:06047ad53505 39 TouchSense sw1(p15),sw2(p16),sw3(p17),sw4(p18);
jk1lot 0:06047ad53505 40
jk1lot 1:707a0a314781 41 //圧電スピーカかp20に繋がっている
jk1lot 1:707a0a314781 42 //このボードのメインターゲットの MyARM基板では p20をPWMに出来るらしいけど
jk1lot 1:707a0a314781 43 //mbed1768では PWMに出来ないので DigitalOutで使用
jk1lot 0:06047ad53505 44 class MmASpeaker : public DigitalOut {
jk1lot 0:06047ad53505 45 public:
jk1lot 0:06047ad53505 46 MmASpeaker(PinName p) : DigitalOut(p) {}
jk1lot 0:06047ad53505 47 void beep(int32_t hz=1000, int32_t ms=100) {
jk1lot 0:06047ad53505 48 for(int i=0; i<hz*ms/1000; i++) {
jk1lot 0:06047ad53505 49 write(1);
jk1lot 0:06047ad53505 50 wait_us(1000*1000/hz/2);
jk1lot 0:06047ad53505 51 write(0);
jk1lot 0:06047ad53505 52 wait_us(1000*1000/hz/2);
jk1lot 0:06047ad53505 53 }
jk1lot 0:06047ad53505 54 }
jk1lot 0:06047ad53505 55 };
jk1lot 0:06047ad53505 56 MmASpeaker speaker(p20);
jk1lot 0:06047ad53505 57
jk1lot 0:06047ad53505 58 int main() {
jk1lot 0:06047ad53505 59 lcd.cls();
jk1lot 0:06047ad53505 60 lcd.printf("Hello World!\n");
jk1lot 0:06047ad53505 61 /* SDカードのテストをするときにはコメントを外してね
jk1lot 0:06047ad53505 62 mkdir("/sd/mydir", 0777);
jk1lot 0:06047ad53505 63 FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
jk1lot 0:06047ad53505 64 if(fp == NULL) {
jk1lot 0:06047ad53505 65 error("Could not open file for write\n");
jk1lot 0:06047ad53505 66 }
jk1lot 0:06047ad53505 67 fprintf(fp, "Hello fun SD Card World!");
jk1lot 0:06047ad53505 68 fclose(fp);
jk1lot 0:06047ad53505 69 */
jk1lot 0:06047ad53505 70 Times t={0,0,0,0,0,0,0};
jk1lot 0:06047ad53505 71 rtc.setTIME(t);
jk1lot 0:06047ad53505 72 compass.setOffset(0.00, 0.00, 0.00);
jk1lot 0:06047ad53505 73 compass.setScale(1.00, 1.00, 1.00);
jk1lot 0:06047ad53505 74 sw1.calibration();
jk1lot 0:06047ad53505 75 sw2.calibration();
jk1lot 0:06047ad53505 76 sw3.calibration();
jk1lot 0:06047ad53505 77 sw4.calibration();
jk1lot 0:06047ad53505 78 speaker.beep();
jk1lot 0:06047ad53505 79
jk1lot 3:aae83c4bd9a0 80 int iconcounter=0;
jk1lot 0:06047ad53505 81 while(1) {
jk1lot 0:06047ad53505 82 Times t=rtc.getTIME();
jk1lot 0:06047ad53505 83 float hdg = compass.heading();
jk1lot 0:06047ad53505 84 bool s1=sw1.sense(),s2=sw2.sense(),s3=sw3.sense(),s4=sw4.sense();
jk1lot 0:06047ad53505 85
jk1lot 0:06047ad53505 86 if(s1) speaker.beep(200);
jk1lot 0:06047ad53505 87 else if(s2) speaker.beep(400);
jk1lot 0:06047ad53505 88 else if(s3) speaker.beep(800);
jk1lot 0:06047ad53505 89 else if(s4) speaker.beep(1600);
jk1lot 0:06047ad53505 90
jk1lot 0:06047ad53505 91 lcd.locate(0,0);
jk1lot 0:06047ad53505 92 lcd.printf("%d %d %d %d ",s1,s2,s3,s4);
jk1lot 0:06047ad53505 93 lcd.locate(0,1);
jk1lot 3:aae83c4bd9a0 94 lcd.printf("%02X:%02X:%02X %.2f", t.hours, t.minutes, t.seconds, hdg);
jk1lot 3:aae83c4bd9a0 95 lcd.setIcon(icons[iconcounter].address,icons[iconcounter].data);
jk1lot 0:06047ad53505 96 myled = 1;
jk1lot 0:06047ad53505 97 wait(0.2);
jk1lot 0:06047ad53505 98 myled = 0;
jk1lot 0:06047ad53505 99 wait(0.2);
jk1lot 3:aae83c4bd9a0 100 lcd.setIcon(icons[iconcounter].address,0);
jk1lot 3:aae83c4bd9a0 101 if(++iconcounter >= MAXICONS) iconcounter=0;
jk1lot 0:06047ad53505 102 }
jk1lot 0:06047ad53505 103 }