mbed-rtos test programs for DISCO_F746NG. #Test for thread, mutex, semaphore, signals, queues, mail, ISR

Dependencies:   BSP_DISCO_F746NG HC06Bluetooth I2Cdev LCD_DISCO_F746NG MCP2515 MD25 MPU9150 TS_DISCO_F746NG emwin mbed-dev mbed-rtos pca9685 ppCANOpen ros_lib_kinetic

Fork of DISCO-F746NG_rtos_test by sabme ua

Committer:
TuxLeon
Date:
Sun Feb 11 18:41:01 2018 +0000
Revision:
1:1a2290a33f30
Parent:
0:225c1da086a1
first commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mzta 0:225c1da086a1 1 #include "mbed.h"
TuxLeon 1:1a2290a33f30 2 #include "TS_DISCO_F746NG.h"
TuxLeon 1:1a2290a33f30 3 #include "LCD_DISCO_F746NG.h"
TuxLeon 1:1a2290a33f30 4 #include "pca9685.h"
TuxLeon 1:1a2290a33f30 5 #include "I2Cdev.h"
TuxLeon 1:1a2290a33f30 6 #include "MPU9150.h"
TuxLeon 1:1a2290a33f30 7 #include "PinNames.h"
mzta 0:225c1da086a1 8
TuxLeon 1:1a2290a33f30 9 LCD_DISCO_F746NG lcd;
TuxLeon 1:1a2290a33f30 10 TS_DISCO_F746NG ts;
TuxLeon 1:1a2290a33f30 11 //I2C myI2C(I2C_SCL, I2C_SDA);
TuxLeon 1:1a2290a33f30 12 //PCA9685 myPWM(1, &myI2C, 400000.0);
TuxLeon 1:1a2290a33f30 13 PwmOut led(PC_7);
TuxLeon 1:1a2290a33f30 14 I2Cdev* myI2Cdev = new I2Cdev();
TuxLeon 1:1a2290a33f30 15 MPU9150 myImu(*myI2Cdev);
TuxLeon 1:1a2290a33f30 16 Serial pc(USBTX, USBRX);
mzta 0:225c1da086a1 17
TuxLeon 1:1a2290a33f30 18 void callback() {
TuxLeon 1:1a2290a33f30 19 // Note: you need to actually read from the serial to clear the RX interrupt
TuxLeon 1:1a2290a33f30 20 pc.printf("%d\n", pc.getc());
mzta 0:225c1da086a1 21 }
mzta 0:225c1da086a1 22
mzta 0:225c1da086a1 23
TuxLeon 1:1a2290a33f30 24 int main()
TuxLeon 1:1a2290a33f30 25 {
TuxLeon 1:1a2290a33f30 26 pc.baud(115200);
TuxLeon 1:1a2290a33f30 27 pc.attach(&callback);
TuxLeon 1:1a2290a33f30 28 pc.printf("\n\nEEPROM demo started\n");
TuxLeon 1:1a2290a33f30 29
TuxLeon 1:1a2290a33f30 30 TS_StateTypeDef TS_State;
TuxLeon 1:1a2290a33f30 31 uint16_t x, y;
TuxLeon 1:1a2290a33f30 32 uint8_t text[30];
TuxLeon 1:1a2290a33f30 33 uint8_t textColor[50];
TuxLeon 1:1a2290a33f30 34 uint8_t status;
TuxLeon 1:1a2290a33f30 35 uint8_t idx;
TuxLeon 1:1a2290a33f30 36 uint8_t cleared = 0;
TuxLeon 1:1a2290a33f30 37 uint8_t prev_nb_touches = 0;
TuxLeon 1:1a2290a33f30 38 uint8_t color_r = 0;
TuxLeon 1:1a2290a33f30 39 uint8_t color_g = 0;
TuxLeon 1:1a2290a33f30 40 uint8_t color_b = 128;
TuxLeon 1:1a2290a33f30 41 uint32_t color = 0xFF000000;
TuxLeon 1:1a2290a33f30 42 enum EColorState {RED, GREEN, BLUE};
TuxLeon 1:1a2290a33f30 43 float pwmOutput = 0.0;
TuxLeon 1:1a2290a33f30 44 EColorState eColorState = BLUE;
TuxLeon 1:1a2290a33f30 45 bool imuState = false;
mzta 0:225c1da086a1 46
TuxLeon 1:1a2290a33f30 47 led.period_ms(20.0); // 4 second period
TuxLeon 1:1a2290a33f30 48 //led.write(0.50f); // 50% duty cycle, relative to period
TuxLeon 1:1a2290a33f30 49 led.pulsewidth_us(1500);
TuxLeon 1:1a2290a33f30 50 //myPWM.init();
TuxLeon 1:1a2290a33f30 51 //myPWM.set_pwm_duty(0, 50.0);
TuxLeon 1:1a2290a33f30 52 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN DEMO", CENTER_MODE);
TuxLeon 1:1a2290a33f30 53
TuxLeon 1:1a2290a33f30 54 wait(1);
TuxLeon 1:1a2290a33f30 55
TuxLeon 1:1a2290a33f30 56 //myImu.initialize();
TuxLeon 1:1a2290a33f30 57 imuState = myImu.testConnection();
TuxLeon 1:1a2290a33f30 58
TuxLeon 1:1a2290a33f30 59 status = ts.Init(lcd.GetXSize(), lcd.GetYSize());
TuxLeon 1:1a2290a33f30 60 if (status != TS_OK) {
TuxLeon 1:1a2290a33f30 61 lcd.Clear(LCD_COLOR_RED);
TuxLeon 1:1a2290a33f30 62 lcd.SetBackColor(LCD_COLOR_RED);
TuxLeon 1:1a2290a33f30 63 lcd.SetTextColor(LCD_COLOR_WHITE);
TuxLeon 1:1a2290a33f30 64 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE);
TuxLeon 1:1a2290a33f30 65 } else {
TuxLeon 1:1a2290a33f30 66 lcd.Clear(LCD_COLOR_GREEN);
TuxLeon 1:1a2290a33f30 67 lcd.SetBackColor(LCD_COLOR_GREEN);
TuxLeon 1:1a2290a33f30 68 lcd.SetTextColor(LCD_COLOR_WHITE);
TuxLeon 1:1a2290a33f30 69 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE);
TuxLeon 1:1a2290a33f30 70 if( imuState ) {
TuxLeon 1:1a2290a33f30 71 lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"IMU INIT OK", CENTER_MODE);
mzta 0:225c1da086a1 72 }
TuxLeon 1:1a2290a33f30 73 else{
TuxLeon 1:1a2290a33f30 74 lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"IMU INIT Failed", CENTER_MODE);
TuxLeon 1:1a2290a33f30 75 }
mzta 0:225c1da086a1 76 }
mzta 0:225c1da086a1 77
TuxLeon 1:1a2290a33f30 78 wait(1);
TuxLeon 1:1a2290a33f30 79 lcd.Clear(LCD_COLOR_WHITE);
TuxLeon 1:1a2290a33f30 80 lcd.SetFont(&Font12);
TuxLeon 1:1a2290a33f30 81 lcd.SetBackColor(LCD_COLOR_WHITE);
TuxLeon 1:1a2290a33f30 82 lcd.SetTextColor(LCD_COLOR_BLACK);
mzta 0:225c1da086a1 83
TuxLeon 1:1a2290a33f30 84 while(1) {
mzta 0:225c1da086a1 85
TuxLeon 1:1a2290a33f30 86 ts.GetState(&TS_State);
TuxLeon 1:1a2290a33f30 87 if (TS_State.touchDetected) {
TuxLeon 1:1a2290a33f30 88 // Clear lines corresponding to old touches coordinates
TuxLeon 1:1a2290a33f30 89 if (TS_State.touchDetected < prev_nb_touches) {
TuxLeon 1:1a2290a33f30 90 for (idx = (TS_State.touchDetected + 1); idx <= 5; idx++) {
TuxLeon 1:1a2290a33f30 91 lcd.ClearStringLine(idx);
TuxLeon 1:1a2290a33f30 92 }
TuxLeon 1:1a2290a33f30 93 }
TuxLeon 1:1a2290a33f30 94 prev_nb_touches = TS_State.touchDetected;
mzta 0:225c1da086a1 95
TuxLeon 1:1a2290a33f30 96 cleared = 0;
mzta 0:225c1da086a1 97
TuxLeon 1:1a2290a33f30 98 lcd.SetTextColor(LCD_COLOR_BLACK);
TuxLeon 1:1a2290a33f30 99 sprintf((char*)text, "Touches: %d", TS_State.touchDetected);
TuxLeon 1:1a2290a33f30 100 lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
mzta 0:225c1da086a1 101
TuxLeon 1:1a2290a33f30 102 for (idx = 0; idx < TS_State.touchDetected; idx++) {
TuxLeon 1:1a2290a33f30 103 x = TS_State.touchX[idx];
TuxLeon 1:1a2290a33f30 104 y = TS_State.touchY[idx];
TuxLeon 1:1a2290a33f30 105 sprintf((char*)text, "Touch %d: x=%d y=%d", idx+1, x, y);
TuxLeon 1:1a2290a33f30 106 lcd.DisplayStringAt(0, LINE(idx+1), (uint8_t *)&textColor, LEFT_MODE);
TuxLeon 1:1a2290a33f30 107 lcd.DisplayStringAt(0, LINE(idx+2), (uint8_t *)&text, LEFT_MODE);
TuxLeon 1:1a2290a33f30 108
TuxLeon 1:1a2290a33f30 109
TuxLeon 1:1a2290a33f30 110 pwmOutput = (float) (x/480.0);
TuxLeon 1:1a2290a33f30 111 if( pwmOutput > 1.0f )
TuxLeon 1:1a2290a33f30 112 {
TuxLeon 1:1a2290a33f30 113 pwmOutput = 1.0f;
TuxLeon 1:1a2290a33f30 114 }
TuxLeon 1:1a2290a33f30 115 led.pulsewidth_us((int)(pwmOutput*2000 + 500)); // 50% duty cycle, relative to period
TuxLeon 1:1a2290a33f30 116
mzta 0:225c1da086a1 117
TuxLeon 1:1a2290a33f30 118 /**
TuxLeon 1:1a2290a33f30 119 * @brief Sets the LCD text color.
TuxLeon 1:1a2290a33f30 120 * @param Color: Text color code ARGB(8-8-8-8);
TuxLeon 1:1a2290a33f30 121 * @retval None
TuxLeon 1:1a2290a33f30 122 */
TuxLeon 1:1a2290a33f30 123 if( eColorState == BLUE ) {
TuxLeon 1:1a2290a33f30 124 color_b++;
TuxLeon 1:1a2290a33f30 125 if( color_b == 255 ) {
TuxLeon 1:1a2290a33f30 126 eColorState = GREEN;
TuxLeon 1:1a2290a33f30 127 color_b = 0;
TuxLeon 1:1a2290a33f30 128 color_g = 128;
TuxLeon 1:1a2290a33f30 129 }
TuxLeon 1:1a2290a33f30 130 }
TuxLeon 1:1a2290a33f30 131 if( eColorState == GREEN ) {
TuxLeon 1:1a2290a33f30 132 color_g++;
TuxLeon 1:1a2290a33f30 133 if( color_g == 255 ) {
TuxLeon 1:1a2290a33f30 134 eColorState = RED;
TuxLeon 1:1a2290a33f30 135 color_g = 0;
TuxLeon 1:1a2290a33f30 136 color_r = 128;
TuxLeon 1:1a2290a33f30 137 }
TuxLeon 1:1a2290a33f30 138 }
TuxLeon 1:1a2290a33f30 139 if( eColorState == RED ) {
TuxLeon 1:1a2290a33f30 140 color_r++;
TuxLeon 1:1a2290a33f30 141 if( color_r == 255 ) {
TuxLeon 1:1a2290a33f30 142 eColorState = BLUE;
TuxLeon 1:1a2290a33f30 143 color_r = 0;
TuxLeon 1:1a2290a33f30 144 color_b = 128;
TuxLeon 1:1a2290a33f30 145 }
TuxLeon 1:1a2290a33f30 146 }
mzta 0:225c1da086a1 147
TuxLeon 1:1a2290a33f30 148 for(uint8_t i=0; i <255; i++) {
TuxLeon 1:1a2290a33f30 149 lcd.SetTextColor(0xFF000000 + i);
TuxLeon 1:1a2290a33f30 150 lcd.FillCircle(i+100, 100, 5);
TuxLeon 1:1a2290a33f30 151 lcd.SetTextColor(0xFF000000 + (i << 8));
TuxLeon 1:1a2290a33f30 152 lcd.FillCircle(i+100, 150, 5);
TuxLeon 1:1a2290a33f30 153 lcd.SetTextColor(0xFF000000 + (i << 16));
TuxLeon 1:1a2290a33f30 154 lcd.FillCircle(i+100, 200, 5);
TuxLeon 1:1a2290a33f30 155 }
mzta 0:225c1da086a1 156
TuxLeon 1:1a2290a33f30 157 color = 0xFF000000 + (color_r << 16) + (color_g << 8) + color_b;
TuxLeon 1:1a2290a33f30 158 sprintf((char*)textColor, "RED %x GREEN %x BLUE %x Color=0x%x ", color_r, color_g, color_b, color);
TuxLeon 1:1a2290a33f30 159 lcd.DisplayStringAt(0, LINE(idx+1), (uint8_t *)&textColor, LEFT_MODE);
mzta 0:225c1da086a1 160
TuxLeon 1:1a2290a33f30 161 lcd.SetTextColor(color);
TuxLeon 1:1a2290a33f30 162 lcd.FillCircle(TS_State.touchX[0], TS_State.touchY[0], 5);
TuxLeon 1:1a2290a33f30 163 }
mzta 0:225c1da086a1 164
TuxLeon 1:1a2290a33f30 165 // lcd.DrawPixel(TS_State.touchX[0], TS_State.touchY[0], LCD_COLOR_ORANGE);
TuxLeon 1:1a2290a33f30 166 } else {
TuxLeon 1:1a2290a33f30 167 if (!cleared) {
TuxLeon 1:1a2290a33f30 168
TuxLeon 1:1a2290a33f30 169 lcd.Clear(LCD_COLOR_WHITE);
TuxLeon 1:1a2290a33f30 170 sprintf((char*)text, "Touches: 0");
TuxLeon 1:1a2290a33f30 171 pc.printf("Servo: %f\n", pwmOutput*2000+500);
TuxLeon 1:1a2290a33f30 172 lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
TuxLeon 1:1a2290a33f30 173 cleared = 1;
mzta 0:225c1da086a1 174 }
mzta 0:225c1da086a1 175 }
mzta 0:225c1da086a1 176 }
mzta 0:225c1da086a1 177 }