boart test board

Dependencies:   USBDevice mbed-dev lwip

Fork of USBSerial_HelloWorld by Compass Yap

main.cpp

Committer:
ua1arn
Date:
2018-07-24
Revision:
15:825cce18de03
Parent:
13:d838b256c7e0
Child:
16:07f39e7a1cc2

File content as of revision 15:825cce18de03:

#include "mbed.h"
#include "USBSerial.h"


static USBSerial pc(0xFFFF, 0x0002, 0x0001);

//static DigitalOut beep(PB_11);
static PwmOut beep(PB_11);

    /**TIM3 GPIO Configuration    
    PA7     ------> TIM3_CH2
    PB0     ------> TIM3_CH3 !!!!
    PB1     ------> TIM3_CH4
    PB4     ------> TIM3_CH1 
    */
    /**TIM4 GPIO Configuration    
    PD12     ------> TIM4_CH1
    PD13     ------> TIM4_CH2 
    */

static DigitalIn button(PE_2);
static DigitalIn opn_sw(PD_7);
static DigitalOut din(PA_7);
static DigitalOut din_light(PB_1);
static DigitalOut ud_pwm(PD_12);
static DigitalOut lr_pwm(PD_13);
//PwmOut UD_PWM(PD_12);
//PwmOut LR_PWM(PD_13);

static Serial bt(PG_14, PG_9, 9600);    // tx, rx USART6 work
static Serial rfid(PD_5, PD_6, 9600);    // tx, rx USART2 work
static Serial wifi(PA_9, PA_10, 9600);    // tx, rx USART1 work
static Serial fifi2(PB_10, PC_5, 9600);   // tx, rx USART3 - overlap with STDIO USART

#define I2CADDR1 0x5F   // 0xbe
#define I2CADDR2 0x6B   // 0xd6

// LwIP timers support
extern "C" {
    uint32_t sys_now()
    {
      return 0;
    }
    }


static I2C i2c(PB_9, PB_8);

int main(void)
{

    //wifi.baud(115200);
    //wifi2.baud(115200);
    
    //beep.period((float) 0.001);                 //set la periode a 1khz
    //beep.write(50); // duty
    din = 1;
    din_light = 1;
    ud_pwm = 1;
    lr_pwm = 1;

    int i = 1;
    int devices_found;
    uint8_t curr_addr;
    char data[1] = {'\0'};
    pc.printf("\r\n");
    pc.printf("Program begin\r\n");
    wait(1);
    
    while(0) {
        
        devices_found = 0;
        //beep = !beep;
        
        for (i = 0; i < 128; i++) {
            curr_addr = i << 1;
            if (!i2c.write(curr_addr, data, 1)) {
                pc.printf("found device at 0x%x\r\n", curr_addr);
                devices_found++;
            }
            wait(0.2);
        }
        
        pc.printf("%d devices found\r\n", devices_found);
        wait(2);
    }

    while(1) {
        //beep = 1;
        //beep.period((float) 0.001);                 //set la periode a 1khz
        pc.printf("I am a virtual serial port - phase a1, btn=%d\r\n", (int) opn_sw.read());
        wait(1)
           ;
        //beep = 0;
        //BEEP.period((float) 0.002);                 //set la periode a 1khz
       pc.printf("I am a virtual serial port - phase a2, btn=%d\r\n", (int) opn_sw.read());
        wait(1)
          ;
    }
}