thanks to Zoltan Hudak publish the way to use stm32f103c8t6 on mbed. now you can use it with Lidar Lite

Dependencies:   LidarLitev2 mbed-STM32F103C8T6 mbed

Fork of Wii_IRCam_Test by Michael Shimniok

Committer:
shimniok
Date:
Thu Dec 30 07:50:11 2010 +0000
Revision:
0:cf1bc7c313b4
Child:
1:150525e9c21f
Initial revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 0:cf1bc7c313b4 1 #include "mbed.h"
shimniok 0:cf1bc7c313b4 2
shimniok 0:cf1bc7c313b4 3 // Adapted from kako's source code: http://www.kako.com/neta/2008-009/2008-009.html
shimniok 0:cf1bc7c313b4 4 // i2c protocol details from - http://blog.makezine.com/archive/2008/11/hacking_the_wiimote_ir_ca.html
shimniok 0:cf1bc7c313b4 5 // wiring from - http://translate.google.com/translate?u=http://www.kako.com/neta/2007-001/2007-001.html&hl=en&ie=UTF-8&sl=ja&tl=en
shimniok 0:cf1bc7c313b4 6 // obviously mbed is 3.3v so no level translation is needed
shimniok 0:cf1bc7c313b4 7 // using built in i2c on pins 9/10
shimniok 0:cf1bc7c313b4 8 //
shimniok 0:cf1bc7c313b4 9
shimniok 0:cf1bc7c313b4 10 DigitalOut myled(LED1);
shimniok 0:cf1bc7c313b4 11 PwmOut servo(p21);
shimniok 0:cf1bc7c313b4 12 Serial pc(USBTX, USBRX); // tx, rx
shimniok 0:cf1bc7c313b4 13 I2C i2c(p9, p10); // sda, scl
shimniok 0:cf1bc7c313b4 14 const int addr = 0xB0; // define the I2C Address of camera
shimniok 0:cf1bc7c313b4 15
shimniok 0:cf1bc7c313b4 16 void i2c_write2(int addr, char a, char b)
shimniok 0:cf1bc7c313b4 17 {
shimniok 0:cf1bc7c313b4 18 char cmd[2];
shimniok 0:cf1bc7c313b4 19
shimniok 0:cf1bc7c313b4 20 cmd[0] = a;
shimniok 0:cf1bc7c313b4 21 cmd[1] = b;
shimniok 0:cf1bc7c313b4 22 i2c.write(addr, cmd, 2);
shimniok 0:cf1bc7c313b4 23 wait(0.07); // delay 70ms
shimniok 0:cf1bc7c313b4 24 }
shimniok 0:cf1bc7c313b4 25
shimniok 0:cf1bc7c313b4 26 void clock_init()
shimniok 0:cf1bc7c313b4 27 {
shimniok 0:cf1bc7c313b4 28 // set up ~20-25MHz clock on p21
shimniok 0:cf1bc7c313b4 29 LPC_PWM1->TCR = (1 << 1); // Reset counter, disable PWM
shimniok 0:cf1bc7c313b4 30 LPC_SC->PCLKSEL0 &= ~(0x3 << 12);
shimniok 0:cf1bc7c313b4 31 LPC_SC->PCLKSEL0 |= (1 << 12); // Set peripheral clock divider to /1, i.e. system clock
shimniok 0:cf1bc7c313b4 32 LPC_PWM1->MR0 = 4; // Match Register 0 is shared period counter for all PWM1
shimniok 0:cf1bc7c313b4 33 LPC_PWM1->MR6 = 2; // Pin 21 is PWM output 6, so Match Register 6
shimniok 0:cf1bc7c313b4 34 LPC_PWM1->LER |= 1; // Start updating at next period start
shimniok 0:cf1bc7c313b4 35 LPC_PWM1->TCR = (1 << 0) || (1 << 3); // Enable counter and PWM
shimniok 0:cf1bc7c313b4 36 }
shimniok 0:cf1bc7c313b4 37
shimniok 0:cf1bc7c313b4 38 void cam_init()
shimniok 0:cf1bc7c313b4 39 {
shimniok 0:cf1bc7c313b4 40 // Init IR Camera sensor
shimniok 0:cf1bc7c313b4 41 i2c_write2(addr, 0x30, 0x01);
shimniok 0:cf1bc7c313b4 42 pc.printf("+\n");
shimniok 0:cf1bc7c313b4 43 i2c_write2(addr, 0x30, 0x08);
shimniok 0:cf1bc7c313b4 44 i2c_write2(addr, 0x06, 0x90);
shimniok 0:cf1bc7c313b4 45 i2c_write2(addr, 0x08, 0xC0);
shimniok 0:cf1bc7c313b4 46 i2c_write2(addr, 0x1A, 0x40);
shimniok 0:cf1bc7c313b4 47 i2c_write2(addr, 0x33, 0x33);
shimniok 0:cf1bc7c313b4 48 wait(0.1);
shimniok 0:cf1bc7c313b4 49 }
shimniok 0:cf1bc7c313b4 50
shimniok 0:cf1bc7c313b4 51 int main() {
shimniok 0:cf1bc7c313b4 52 char cmd[8];
shimniok 0:cf1bc7c313b4 53 char buf[16];
shimniok 0:cf1bc7c313b4 54 int Ix1,Iy1,Ix2,Iy2;
shimniok 0:cf1bc7c313b4 55 int Ix3,Iy3,Ix4,Iy4;
shimniok 0:cf1bc7c313b4 56 int s;
shimniok 0:cf1bc7c313b4 57
shimniok 0:cf1bc7c313b4 58 clock_init();
shimniok 0:cf1bc7c313b4 59
shimniok 0:cf1bc7c313b4 60 // PC serial output
shimniok 0:cf1bc7c313b4 61 pc.baud(115200);
shimniok 0:cf1bc7c313b4 62 pc.printf("Initializing camera...");
shimniok 0:cf1bc7c313b4 63
shimniok 0:cf1bc7c313b4 64 cam_init();
shimniok 0:cf1bc7c313b4 65
shimniok 0:cf1bc7c313b4 66 pc.printf("complete\n");
shimniok 0:cf1bc7c313b4 67
shimniok 0:cf1bc7c313b4 68 // read I2C stuff
shimniok 0:cf1bc7c313b4 69 while(1) {
shimniok 0:cf1bc7c313b4 70 myled = 1;
shimniok 0:cf1bc7c313b4 71 // IR Sensor read
shimniok 0:cf1bc7c313b4 72 cmd[0] = 0x36;
shimniok 0:cf1bc7c313b4 73 i2c.write(addr, cmd, 1);
shimniok 0:cf1bc7c313b4 74 i2c.read(addr, buf, 16); // read the 16-byte result
shimniok 0:cf1bc7c313b4 75
shimniok 0:cf1bc7c313b4 76 myled = 0;
shimniok 0:cf1bc7c313b4 77
shimniok 0:cf1bc7c313b4 78 Ix1 = buf[1];
shimniok 0:cf1bc7c313b4 79 Iy1 = buf[2];
shimniok 0:cf1bc7c313b4 80 s = buf[3];
shimniok 0:cf1bc7c313b4 81 Ix1 += (s & 0x30) <<4;
shimniok 0:cf1bc7c313b4 82 Iy1 += (s & 0xC0) <<2;
shimniok 0:cf1bc7c313b4 83
shimniok 0:cf1bc7c313b4 84 Ix2 = buf[4];
shimniok 0:cf1bc7c313b4 85 Iy2 = buf[5];
shimniok 0:cf1bc7c313b4 86 s = buf[6];
shimniok 0:cf1bc7c313b4 87 Ix2 += (s & 0x30) <<4;
shimniok 0:cf1bc7c313b4 88 Iy2 += (s & 0xC0) <<2;
shimniok 0:cf1bc7c313b4 89
shimniok 0:cf1bc7c313b4 90 Ix3 = buf[7];
shimniok 0:cf1bc7c313b4 91 Iy3 = buf[8];
shimniok 0:cf1bc7c313b4 92 s = buf[9];
shimniok 0:cf1bc7c313b4 93 Ix3 += (s & 0x30) <<4;
shimniok 0:cf1bc7c313b4 94 Iy3 += (s & 0xC0) <<2;
shimniok 0:cf1bc7c313b4 95
shimniok 0:cf1bc7c313b4 96 Ix4 = buf[10];
shimniok 0:cf1bc7c313b4 97 Iy4 = buf[11];
shimniok 0:cf1bc7c313b4 98 s = buf[12];
shimniok 0:cf1bc7c313b4 99 Ix4 += (s & 0x30) <<4;
shimniok 0:cf1bc7c313b4 100 Iy4 += (s & 0xC0) <<2;
shimniok 0:cf1bc7c313b4 101
shimniok 0:cf1bc7c313b4 102 // print the coordinate data
shimniok 0:cf1bc7c313b4 103 pc.printf("Ix1: %4d, Iy1: %4d\n", Ix1, Iy1 );
shimniok 0:cf1bc7c313b4 104 pc.printf("Ix2: %4d, Iy2: %4d\n", Ix2, Iy2 );
shimniok 0:cf1bc7c313b4 105
shimniok 0:cf1bc7c313b4 106 wait(0.250);
shimniok 0:cf1bc7c313b4 107 }
shimniok 0:cf1bc7c313b4 108
shimniok 0:cf1bc7c313b4 109 }