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:
Sun Jun 12 15:03:15 2016 +0000
Revision:
4:faf01cf17d60
Parent:
3:aae83c4bd9a0
rewrite LSM303DHLC

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 4:faf01cf17d60 12 #include "LSM303DLHC.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 4:faf01cf17d60 33
jk1lot 0:06047ad53505 34 RX8025 rtc(i2c);
jk1lot 4:faf01cf17d60 35 LSM303DLHC compass(&i2c);
jk1lot 4:faf01cf17d60 36
jk1lot 4:faf01cf17d60 37 /* SD filesystem with card detection
jk1lot 4:faf01cf17d60 38 */
jk1lot 4:faf01cf17d60 39 class SDFileSystemCD : public SDFileSystem {
jk1lot 4:faf01cf17d60 40 DigitalIn card_detect;
jk1lot 4:faf01cf17d60 41 public:
jk1lot 4:faf01cf17d60 42 SDFileSystemCD(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName cd, const char* name)
jk1lot 4:faf01cf17d60 43 : SDFileSystem(p5, p6, p7, p22, "sd"), card_detect(cd, PullUp) {
jk1lot 4:faf01cf17d60 44 }
jk1lot 4:faf01cf17d60 45 bool cardExist(void) { return card_detect==0; }
jk1lot 4:faf01cf17d60 46 };
jk1lot 4:faf01cf17d60 47 SDFileSystemCD sd(p5, p6, p7, p22, p29, "sd");
jk1lot 1:707a0a314781 48
jk1lot 1:707a0a314781 49 //基板の裏側に触らないと ONにならない
jk1lot 1:707a0a314781 50 //構造的にそういう仕様っぽいけど、どうなんだろ?
jk1lot 0:06047ad53505 51 TouchSense sw1(p15),sw2(p16),sw3(p17),sw4(p18);
jk1lot 0:06047ad53505 52
jk1lot 1:707a0a314781 53 //圧電スピーカかp20に繋がっている
jk1lot 1:707a0a314781 54 //このボードのメインターゲットの MyARM基板では p20をPWMに出来るらしいけど
jk1lot 1:707a0a314781 55 //mbed1768では PWMに出来ないので DigitalOutで使用
jk1lot 0:06047ad53505 56 class MmASpeaker : public DigitalOut {
jk1lot 0:06047ad53505 57 public:
jk1lot 0:06047ad53505 58 MmASpeaker(PinName p) : DigitalOut(p) {}
jk1lot 0:06047ad53505 59 void beep(int32_t hz=1000, int32_t ms=100) {
jk1lot 0:06047ad53505 60 for(int i=0; i<hz*ms/1000; i++) {
jk1lot 0:06047ad53505 61 write(1);
jk1lot 0:06047ad53505 62 wait_us(1000*1000/hz/2);
jk1lot 0:06047ad53505 63 write(0);
jk1lot 0:06047ad53505 64 wait_us(1000*1000/hz/2);
jk1lot 0:06047ad53505 65 }
jk1lot 0:06047ad53505 66 }
jk1lot 0:06047ad53505 67 };
jk1lot 0:06047ad53505 68 MmASpeaker speaker(p20);
jk1lot 0:06047ad53505 69
jk1lot 0:06047ad53505 70 int main() {
jk1lot 4:faf01cf17d60 71 lcd.setContrast(32);
jk1lot 0:06047ad53505 72 lcd.cls();
jk1lot 4:faf01cf17d60 73 lcd.printf("Hello World!");
jk1lot 4:faf01cf17d60 74 lcd.locate(0,1);
jk1lot 4:faf01cf17d60 75 if(sd.cardExist()) {
jk1lot 4:faf01cf17d60 76 lcd.printf("SDcard Exist");
jk1lot 4:faf01cf17d60 77 mkdir("/sd/mydir", 0777);
jk1lot 4:faf01cf17d60 78 FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
jk1lot 4:faf01cf17d60 79 if(fp == NULL) {
jk1lot 4:faf01cf17d60 80 error("Could not open file for write\n");
jk1lot 4:faf01cf17d60 81 }
jk1lot 4:faf01cf17d60 82 fprintf(fp, "Hello fun SD Card World!");
jk1lot 4:faf01cf17d60 83 fclose(fp);
jk1lot 4:faf01cf17d60 84 } else lcd.printf("No SDcard");
jk1lot 0:06047ad53505 85 Times t={0,0,0,0,0,0,0};
jk1lot 0:06047ad53505 86 rtc.setTIME(t);
jk1lot 0:06047ad53505 87 sw1.calibration();
jk1lot 0:06047ad53505 88 sw2.calibration();
jk1lot 0:06047ad53505 89 sw3.calibration();
jk1lot 0:06047ad53505 90 sw4.calibration();
jk1lot 4:faf01cf17d60 91 wait(3.0);
jk1lot 0:06047ad53505 92 speaker.beep();
jk1lot 0:06047ad53505 93
jk1lot 3:aae83c4bd9a0 94 int iconcounter=0;
jk1lot 0:06047ad53505 95 while(1) {
jk1lot 0:06047ad53505 96 Times t=rtc.getTIME();
jk1lot 4:faf01cf17d60 97 compass.getAccel();
jk1lot 4:faf01cf17d60 98 compass.getMagnet();
jk1lot 4:faf01cf17d60 99 int sw=(((sw1.sense()<<1 | sw2.sense())<<1) | sw3.sense())<<1 |sw4.sense();
jk1lot 4:faf01cf17d60 100 speaker.beep(1600/sw);
jk1lot 0:06047ad53505 101
jk1lot 0:06047ad53505 102 lcd.locate(0,0);
jk1lot 4:faf01cf17d60 103 lcd.printf("%1x %.1f %d ", sw, compass.temperature(), compass.accelX());
jk1lot 0:06047ad53505 104 lcd.locate(0,1);
jk1lot 4:faf01cf17d60 105 lcd.printf("%02X:%02X:%02X %.1f", t.hours, t.minutes, t.seconds, compass.orientation());
jk1lot 4:faf01cf17d60 106 lcd.clrIcon();
jk1lot 3:aae83c4bd9a0 107 lcd.setIcon(icons[iconcounter].address,icons[iconcounter].data);
jk1lot 4:faf01cf17d60 108 if(++iconcounter >= MAXICONS) iconcounter=0;
jk1lot 0:06047ad53505 109 myled = 1;
jk1lot 0:06047ad53505 110 wait(0.2);
jk1lot 0:06047ad53505 111 myled = 0;
jk1lot 0:06047ad53505 112 wait(0.2);
jk1lot 0:06047ad53505 113 }
jk1lot 0:06047ad53505 114 }