Test
Dependencies: BSP_DISCO_F429ZI LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI
main.cpp@1:39992c325c58, 2017-07-24 (annotated)
- Committer:
- jimk3038
- Date:
- Mon Jul 24 12:48:26 2017 +0000
- Revision:
- 1:39992c325c58
- Parent:
- 0:a564383a9b15
Ready for share.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jimk3038 | 1:39992c325c58 | 1 | // |
jimk3038 | 1:39992c325c58 | 2 | // Powerhouse Electronics - Fluid Dispense System |
jimk3038 | 1:39992c325c58 | 3 | // By: Jim Kemp June 6th, 2017 |
jimk3038 | 1:39992c325c58 | 4 | // |
jimk3038 | 1:39992c325c58 | 5 | // Notes: Screen Size: 240x320 |
jimk3038 | 1:39992c325c58 | 6 | |
jimk3038 | 1:39992c325c58 | 7 | #include "TS_DISCO_F429ZI.h" |
jimk3038 | 1:39992c325c58 | 8 | #include "LCD_DISCO_F429ZI.h" |
jimk3038 | 0:a564383a9b15 | 9 | #include "mbed.h" |
jimk3038 | 1:39992c325c58 | 10 | |
jimk3038 | 1:39992c325c58 | 11 | #define FLASH_USER_START_ADDR FLASH_SECTOR_10 /* Start @ of user Flash area */ |
jimk3038 | 1:39992c325c58 | 12 | #define FLASH_USER_END_ADDR FLASH_SECTOR_11 /* End @ of user Flash area */ |
jimk3038 | 1:39992c325c58 | 13 | |
jimk3038 | 1:39992c325c58 | 14 | #define TS_IDLE 15 // Reset for touch screen idle. On idle, save values. |
jimk3038 | 1:39992c325c58 | 15 | //#define BUFFER_SIZE ((uint32_t)0x0100) |
jimk3038 | 1:39992c325c58 | 16 | //#define WRITE_READ_ADDR ((uint32_t)0x0800) |
jimk3038 | 1:39992c325c58 | 17 | #define WRITE_READ_ADDR ((uint32_t)0x0000) |
jimk3038 | 0:a564383a9b15 | 18 | |
jimk3038 | 0:a564383a9b15 | 19 | LCD_DISCO_F429ZI lcd; |
jimk3038 | 1:39992c325c58 | 20 | TS_DISCO_F429ZI ts; |
jimk3038 | 1:39992c325c58 | 21 | Timer tsTimer; |
jimk3038 | 0:a564383a9b15 | 22 | |
jimk3038 | 0:a564383a9b15 | 23 | DigitalOut led1(LED1); |
jimk3038 | 1:39992c325c58 | 24 | bool tsPress( uint16_t *x, uint16_t *y ); |
jimk3038 | 0:a564383a9b15 | 25 | |
jimk3038 | 1:39992c325c58 | 26 | // Used to define a bounding box by x,y and width, height. |
jimk3038 | 1:39992c325c58 | 27 | typedef struct { |
jimk3038 | 1:39992c325c58 | 28 | uint16_t x, y; |
jimk3038 | 1:39992c325c58 | 29 | uint16_t width, height; |
jimk3038 | 1:39992c325c58 | 30 | } box; |
jimk3038 | 1:39992c325c58 | 31 | |
jimk3038 | 1:39992c325c58 | 32 | // Used to define a point. |
jimk3038 | 1:39992c325c58 | 33 | typedef struct { |
jimk3038 | 1:39992c325c58 | 34 | uint16_t x, y; |
jimk3038 | 1:39992c325c58 | 35 | } pt; |
jimk3038 | 1:39992c325c58 | 36 | |
jimk3038 | 1:39992c325c58 | 37 | typedef enum { P0, P1, P2, P3, INC, DEC, NONE } winLocs_t; |
jimk3038 | 1:39992c325c58 | 38 | |
jimk3038 | 1:39992c325c58 | 39 | const box butLeft = { 0, 270, 110, 50 }; |
jimk3038 | 1:39992c325c58 | 40 | const box butRight = { 130, 270, 110, 50 }; |
jimk3038 | 1:39992c325c58 | 41 | const box parm0Win = { 0,0, 239, 55 }; |
jimk3038 | 1:39992c325c58 | 42 | const box parm1Win = { 0,60, 239, 55 }; |
jimk3038 | 1:39992c325c58 | 43 | const box parm2Win = { 0,120, 239, 55 }; |
jimk3038 | 1:39992c325c58 | 44 | const box parm3Win = { 0,180, 239, 55 }; |
jimk3038 | 1:39992c325c58 | 45 | |
jimk3038 | 1:39992c325c58 | 46 | static void SystemClock_Config(); |
jimk3038 | 1:39992c325c58 | 47 | bool testTouch( uint16_t x, uint16_t y, box b ); |
jimk3038 | 1:39992c325c58 | 48 | void myFillRect( LCD_DISCO_F429ZI lcd, box b ); |
jimk3038 | 1:39992c325c58 | 49 | void myDrawRect( LCD_DISCO_F429ZI lcd, box b, uint32_t color ); |
jimk3038 | 1:39992c325c58 | 50 | void dispParm( LCD_DISCO_F429ZI lcd, uint8_t parmNum, char *s, char *units, float val ); |
jimk3038 | 1:39992c325c58 | 51 | winLocs_t locateTouch( uint16_t x, uint16_t y ); |
jimk3038 | 1:39992c325c58 | 52 | |
jimk3038 | 1:39992c325c58 | 53 | uint32_t FirstSector = 0, NbOfSectors = 0, Address = 0; |
jimk3038 | 1:39992c325c58 | 54 | uint32_t SectorError = 0; |
jimk3038 | 1:39992c325c58 | 55 | __IO uint32_t data32 = 0 , MemoryProgramStatus = 0; |
jimk3038 | 1:39992c325c58 | 56 | |
jimk3038 | 1:39992c325c58 | 57 | int main() { |
jimk3038 | 1:39992c325c58 | 58 | led1 = 1; |
jimk3038 | 1:39992c325c58 | 59 | //char s[20]; |
jimk3038 | 1:39992c325c58 | 60 | float cnt=20.0f, cnt2=12.0f, chg=0.1f; |
jimk3038 | 1:39992c325c58 | 61 | uint8_t status; |
jimk3038 | 1:39992c325c58 | 62 | uint16_t x=0, y=0; // Touch Screen X/Y coord. |
jimk3038 | 1:39992c325c58 | 63 | uint8_t tsFast=0; // Switch to fast change after a long touch. |
jimk3038 | 1:39992c325c58 | 64 | uint8_t tsIdle=0; // After changes are made, on idle save values. |
jimk3038 | 1:39992c325c58 | 65 | winLocs_t activeWin = NONE; |
jimk3038 | 1:39992c325c58 | 66 | uint32_t vals[10]; |
jimk3038 | 1:39992c325c58 | 67 | |
jimk3038 | 1:39992c325c58 | 68 | FLASH_EraseInitTypeDef EraseInitStruct; |
jimk3038 | 1:39992c325c58 | 69 | |
jimk3038 | 1:39992c325c58 | 70 | HAL_Init(); |
jimk3038 | 1:39992c325c58 | 71 | SystemClock_Config(); |
jimk3038 | 1:39992c325c58 | 72 | //wait( 1 ); |
jimk3038 | 1:39992c325c58 | 73 | |
jimk3038 | 1:39992c325c58 | 74 | //vals[0] = (uint32_t)0; |
jimk3038 | 1:39992c325c58 | 75 | //vals[1] = (uint32_t)0; |
jimk3038 | 1:39992c325c58 | 76 | vals[0] = (uint32_t)222; |
jimk3038 | 1:39992c325c58 | 77 | vals[1] = (uint32_t)111; |
jimk3038 | 1:39992c325c58 | 78 | wait_ms( 50 ); |
jimk3038 | 1:39992c325c58 | 79 | |
jimk3038 | 1:39992c325c58 | 80 | FirstSector = FLASH_USER_START_ADDR; |
jimk3038 | 1:39992c325c58 | 81 | /* Get the number of sector to erase from 1st sector*/ |
jimk3038 | 1:39992c325c58 | 82 | NbOfSectors = FLASH_USER_END_ADDR - FirstSector + 1; |
jimk3038 | 1:39992c325c58 | 83 | |
jimk3038 | 1:39992c325c58 | 84 | /* Fill EraseInit structure*/ |
jimk3038 | 1:39992c325c58 | 85 | EraseInitStruct.TypeErase = TYPEERASE_SECTORS; |
jimk3038 | 1:39992c325c58 | 86 | EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3; |
jimk3038 | 1:39992c325c58 | 87 | EraseInitStruct.Sector = FirstSector; |
jimk3038 | 1:39992c325c58 | 88 | EraseInitStruct.NbSectors = NbOfSectors; |
jimk3038 | 1:39992c325c58 | 89 | |
jimk3038 | 1:39992c325c58 | 90 | HAL_FLASH_Unlock(); |
jimk3038 | 1:39992c325c58 | 91 | __HAL_FLASH_CLEAR_FLAG( FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
jimk3038 | 1:39992c325c58 | 92 | | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR ); |
jimk3038 | 1:39992c325c58 | 93 | //FLASH_Erase_Sector( FLASH_USER_START_ADDR, VOLTAGE_RANGE_3 ); |
jimk3038 | 1:39992c325c58 | 94 | HAL_FLASHEx_Erase( &EraseInitStruct, &SectorError ); |
jimk3038 | 1:39992c325c58 | 95 | |
jimk3038 | 1:39992c325c58 | 96 | Address = FLASH_USER_START_ADDR; |
jimk3038 | 1:39992c325c58 | 97 | HAL_FLASH_Program( TYPEPROGRAM_WORD, Address, vals[0]); |
jimk3038 | 1:39992c325c58 | 98 | HAL_FLASH_Program( TYPEPROGRAM_WORD, Address+4, vals[1]); |
jimk3038 | 1:39992c325c58 | 99 | HAL_FLASH_Lock(); |
jimk3038 | 1:39992c325c58 | 100 | |
jimk3038 | 1:39992c325c58 | 101 | lcd.Clear( LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 102 | lcd.SetBackColor( LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 103 | lcd.SetTextColor( LCD_COLOR_WHITE ); |
jimk3038 | 1:39992c325c58 | 104 | BSP_LCD_SetFont( &Font20 ); |
jimk3038 | 1:39992c325c58 | 105 | lcd.DisplayStringAt( 0, LINE(4), (uint8_t *)"Powerhouse-", LEFT_MODE ); |
jimk3038 | 1:39992c325c58 | 106 | lcd.DisplayStringAt( 0, LINE(5), (uint8_t *)"Electronics", CENTER_MODE ); |
jimk3038 | 1:39992c325c58 | 107 | BSP_LCD_SetFont( &Font24 ); |
jimk3038 | 1:39992c325c58 | 108 | lcd.DisplayStringAt( 0, LINE(8), (uint8_t *)"Ph-Elec.com", CENTER_MODE ); |
jimk3038 | 1:39992c325c58 | 109 | printf( "\nPowerhouse Electronics\n" ); |
jimk3038 | 1:39992c325c58 | 110 | printf( "Dispencer System\n" ); |
jimk3038 | 1:39992c325c58 | 111 | |
jimk3038 | 1:39992c325c58 | 112 | Address = FLASH_USER_START_ADDR; |
jimk3038 | 1:39992c325c58 | 113 | vals[0] = *(__IO uint32_t*)Address; |
jimk3038 | 1:39992c325c58 | 114 | vals[1] = *(__IO uint32_t*)(Address+4); |
jimk3038 | 1:39992c325c58 | 115 | |
jimk3038 | 1:39992c325c58 | 116 | printf( "Read Data Done: %d %d\n", (int16_t)vals[0], (int16_t)vals[1] ); |
jimk3038 | 1:39992c325c58 | 117 | |
jimk3038 | 1:39992c325c58 | 118 | wait( 1 ); |
jimk3038 | 1:39992c325c58 | 119 | |
jimk3038 | 1:39992c325c58 | 120 | lcd.Clear(LCD_COLOR_BLACK); |
jimk3038 | 1:39992c325c58 | 121 | status = ts.Init( lcd.GetXSize(), lcd.GetYSize() ); |
jimk3038 | 1:39992c325c58 | 122 | if ( status != TS_OK ) { |
jimk3038 | 1:39992c325c58 | 123 | lcd.Clear(LCD_COLOR_RED); |
jimk3038 | 1:39992c325c58 | 124 | lcd.SetBackColor(LCD_COLOR_RED); |
jimk3038 | 1:39992c325c58 | 125 | lcd.SetTextColor(LCD_COLOR_WHITE); |
jimk3038 | 1:39992c325c58 | 126 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE); |
jimk3038 | 1:39992c325c58 | 127 | lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"INIT FAIL", CENTER_MODE); |
jimk3038 | 1:39992c325c58 | 128 | while ( 1 ); |
jimk3038 | 1:39992c325c58 | 129 | } |
jimk3038 | 0:a564383a9b15 | 130 | |
jimk3038 | 1:39992c325c58 | 131 | printf( "Screen Size: %d / %d\n", lcd.GetXSize(), lcd.GetYSize() ); |
jimk3038 | 1:39992c325c58 | 132 | |
jimk3038 | 1:39992c325c58 | 133 | lcd.SetTextColor(LCD_COLOR_BLUE); |
jimk3038 | 1:39992c325c58 | 134 | myFillRect( lcd, butLeft ); |
jimk3038 | 1:39992c325c58 | 135 | myFillRect( lcd, butRight ); |
jimk3038 | 1:39992c325c58 | 136 | lcd.SetBackColor(LCD_COLOR_BLUE); |
jimk3038 | 1:39992c325c58 | 137 | lcd.SetTextColor(LCD_COLOR_WHITE); |
jimk3038 | 1:39992c325c58 | 138 | BSP_LCD_SetFont(&Font24); |
jimk3038 | 1:39992c325c58 | 139 | lcd.DisplayStringAt( 20, LINE(12), (uint8_t *)"Inc.", LEFT_MODE); |
jimk3038 | 1:39992c325c58 | 140 | lcd.DisplayStringAt( 160, LINE(12), (uint8_t *)"Dec.", LEFT_MODE); |
jimk3038 | 1:39992c325c58 | 141 | lcd.SetBackColor(LCD_COLOR_BLACK); |
jimk3038 | 1:39992c325c58 | 142 | |
jimk3038 | 1:39992c325c58 | 143 | while ( 1 ) { |
jimk3038 | 1:39992c325c58 | 144 | |
jimk3038 | 1:39992c325c58 | 145 | if ( tsPress( &x, &y ) ) { |
jimk3038 | 1:39992c325c58 | 146 | if ( activeWin == P0 ) { |
jimk3038 | 1:39992c325c58 | 147 | if ( testTouch( x,y, butLeft ) ) { |
jimk3038 | 1:39992c325c58 | 148 | cnt += chg; |
jimk3038 | 1:39992c325c58 | 149 | if ( cnt >= 1000.0f ) cnt = 999.9f; |
jimk3038 | 1:39992c325c58 | 150 | } |
jimk3038 | 1:39992c325c58 | 151 | if ( testTouch( x,y, butRight ) ) { |
jimk3038 | 1:39992c325c58 | 152 | cnt -= chg; |
jimk3038 | 1:39992c325c58 | 153 | if ( cnt < 0.0f ) cnt = 0.0f; |
jimk3038 | 1:39992c325c58 | 154 | } |
jimk3038 | 1:39992c325c58 | 155 | } |
jimk3038 | 1:39992c325c58 | 156 | |
jimk3038 | 1:39992c325c58 | 157 | if ( activeWin == P1 ) { |
jimk3038 | 1:39992c325c58 | 158 | if ( testTouch( x,y, butLeft ) ) { |
jimk3038 | 1:39992c325c58 | 159 | cnt2 += chg; |
jimk3038 | 1:39992c325c58 | 160 | if ( cnt2 >= 1000.0f ) cnt2 = 999.9f; |
jimk3038 | 1:39992c325c58 | 161 | } |
jimk3038 | 1:39992c325c58 | 162 | if ( testTouch( x,y, butRight ) ) { |
jimk3038 | 1:39992c325c58 | 163 | cnt2 -= chg; |
jimk3038 | 1:39992c325c58 | 164 | if ( cnt2 < 0.0f ) cnt2 = 0.0f; |
jimk3038 | 1:39992c325c58 | 165 | } |
jimk3038 | 1:39992c325c58 | 166 | } |
jimk3038 | 1:39992c325c58 | 167 | |
jimk3038 | 1:39992c325c58 | 168 | tsFast += 1; |
jimk3038 | 1:39992c325c58 | 169 | if ( tsFast > 5 ) chg = 1.0; |
jimk3038 | 1:39992c325c58 | 170 | if ( tsFast > 25 ) chg = 10.0; |
jimk3038 | 1:39992c325c58 | 171 | if ( tsFast > 50 ) chg = 100.0; |
jimk3038 | 1:39992c325c58 | 172 | tsIdle = TS_IDLE; |
jimk3038 | 1:39992c325c58 | 173 | } |
jimk3038 | 1:39992c325c58 | 174 | else { |
jimk3038 | 1:39992c325c58 | 175 | tsFast = 0; |
jimk3038 | 1:39992c325c58 | 176 | chg = 0.1f; |
jimk3038 | 1:39992c325c58 | 177 | if ( tsIdle == 1 ) printf( "Save Values...\n" ); |
jimk3038 | 1:39992c325c58 | 178 | if ( tsIdle ) --tsIdle; |
jimk3038 | 1:39992c325c58 | 179 | } |
jimk3038 | 1:39992c325c58 | 180 | |
jimk3038 | 1:39992c325c58 | 181 | // Update faster and faster when the ts is held down long. |
jimk3038 | 1:39992c325c58 | 182 | if ( tsFast < 5 ) wait( 0.3 ); |
jimk3038 | 1:39992c325c58 | 183 | else if ( tsFast < 20 ) wait( 0.2 ); |
jimk3038 | 1:39992c325c58 | 184 | else wait( 0.1 ); |
jimk3038 | 0:a564383a9b15 | 185 | |
jimk3038 | 1:39992c325c58 | 186 | dispParm( lcd, 0, "Dispense Speed:", "mm/min", cnt ); |
jimk3038 | 1:39992c325c58 | 187 | dispParm( lcd, 1, "PreFill Dist:", "mm", cnt2 ); |
jimk3038 | 1:39992c325c58 | 188 | dispParm( lcd, 2, "PostRetact Dist:", "mm", 12.0f ); |
jimk3038 | 1:39992c325c58 | 189 | dispParm( lcd, 3, "Pre/Post Speed:", "mm/min", 100.0f ); |
jimk3038 | 1:39992c325c58 | 190 | |
jimk3038 | 1:39992c325c58 | 191 | if( tsIdle == TS_IDLE ) { |
jimk3038 | 1:39992c325c58 | 192 | if( (locateTouch( x,y ) == P0) && (activeWin != P0) ) { |
jimk3038 | 1:39992c325c58 | 193 | printf( "P0 Selected.\n" ); |
jimk3038 | 1:39992c325c58 | 194 | activeWin = P0; |
jimk3038 | 1:39992c325c58 | 195 | myDrawRect( lcd, parm0Win, LCD_COLOR_RED ); |
jimk3038 | 1:39992c325c58 | 196 | myDrawRect( lcd, parm1Win, LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 197 | myDrawRect( lcd, parm2Win, LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 198 | myDrawRect( lcd, parm3Win, LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 199 | } |
jimk3038 | 1:39992c325c58 | 200 | |
jimk3038 | 1:39992c325c58 | 201 | if( (locateTouch( x,y ) == P1) && (activeWin != P1) ) { |
jimk3038 | 1:39992c325c58 | 202 | printf( "P1 Selected.\n" ); |
jimk3038 | 1:39992c325c58 | 203 | activeWin = P1; |
jimk3038 | 1:39992c325c58 | 204 | myDrawRect( lcd, parm0Win, LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 205 | myDrawRect( lcd, parm1Win, LCD_COLOR_RED ); |
jimk3038 | 1:39992c325c58 | 206 | myDrawRect( lcd, parm2Win, LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 207 | myDrawRect( lcd, parm3Win, LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 208 | } |
jimk3038 | 0:a564383a9b15 | 209 | |
jimk3038 | 1:39992c325c58 | 210 | if( (locateTouch( x,y ) == P2) && (activeWin != P2) ) { |
jimk3038 | 1:39992c325c58 | 211 | printf( "P2 Selected.\n" ); |
jimk3038 | 1:39992c325c58 | 212 | activeWin = P2; |
jimk3038 | 1:39992c325c58 | 213 | myDrawRect( lcd, parm0Win, LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 214 | myDrawRect( lcd, parm1Win, LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 215 | myDrawRect( lcd, parm2Win, LCD_COLOR_RED ); |
jimk3038 | 1:39992c325c58 | 216 | myDrawRect( lcd, parm3Win, LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 217 | } |
jimk3038 | 1:39992c325c58 | 218 | |
jimk3038 | 1:39992c325c58 | 219 | if( (locateTouch( x,y ) == P3) && (activeWin != P3) ) { |
jimk3038 | 1:39992c325c58 | 220 | printf( "P3 Selected.\n" ); |
jimk3038 | 1:39992c325c58 | 221 | activeWin = P3; |
jimk3038 | 1:39992c325c58 | 222 | myDrawRect( lcd, parm0Win, LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 223 | myDrawRect( lcd, parm1Win, LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 224 | myDrawRect( lcd, parm2Win, LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 225 | myDrawRect( lcd, parm3Win, LCD_COLOR_RED ); |
jimk3038 | 1:39992c325c58 | 226 | } |
jimk3038 | 1:39992c325c58 | 227 | } |
jimk3038 | 1:39992c325c58 | 228 | if ( tsIdle == 1 ) { |
jimk3038 | 1:39992c325c58 | 229 | if( activeWin != NONE ) { |
jimk3038 | 1:39992c325c58 | 230 | myDrawRect( lcd, parm0Win, LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 231 | myDrawRect( lcd, parm1Win, LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 232 | myDrawRect( lcd, parm2Win, LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 233 | myDrawRect( lcd, parm3Win, LCD_COLOR_BLACK ); |
jimk3038 | 1:39992c325c58 | 234 | activeWin = NONE; |
jimk3038 | 1:39992c325c58 | 235 | } |
jimk3038 | 1:39992c325c58 | 236 | } |
jimk3038 | 1:39992c325c58 | 237 | |
jimk3038 | 1:39992c325c58 | 238 | led1 = !led1; |
jimk3038 | 1:39992c325c58 | 239 | } |
jimk3038 | 0:a564383a9b15 | 240 | } |
jimk3038 | 0:a564383a9b15 | 241 | |
jimk3038 | 1:39992c325c58 | 242 | // ============================================================================ |
jimk3038 | 1:39992c325c58 | 243 | winLocs_t locateTouch( uint16_t x, uint16_t y ) { |
jimk3038 | 1:39992c325c58 | 244 | if( testTouch( x,y, parm0Win ) ) return P0; |
jimk3038 | 1:39992c325c58 | 245 | if( testTouch( x,y, parm1Win ) ) return P1; |
jimk3038 | 1:39992c325c58 | 246 | if( testTouch( x,y, parm2Win ) ) return P2; |
jimk3038 | 1:39992c325c58 | 247 | if( testTouch( x,y, parm3Win ) ) return P3; |
jimk3038 | 1:39992c325c58 | 248 | return NONE; |
jimk3038 | 1:39992c325c58 | 249 | } |
jimk3038 | 1:39992c325c58 | 250 | |
jimk3038 | 1:39992c325c58 | 251 | // Paint a parameter on the screen. |
jimk3038 | 1:39992c325c58 | 252 | // ============================================================================ |
jimk3038 | 1:39992c325c58 | 253 | void dispParm( LCD_DISCO_F429ZI lcd, uint8_t parmNum, char *s, char *units, float val ) { |
jimk3038 | 1:39992c325c58 | 254 | char str[20]; |
jimk3038 | 1:39992c325c58 | 255 | uint16_t y = parmNum * 60; |
jimk3038 | 1:39992c325c58 | 256 | //box p; |
jimk3038 | 1:39992c325c58 | 257 | |
jimk3038 | 1:39992c325c58 | 258 | BSP_LCD_SetFont( &Font20 ); |
jimk3038 | 1:39992c325c58 | 259 | lcd.DisplayStringAt(4, y+6, (uint8_t *)s, LEFT_MODE ); |
jimk3038 | 1:39992c325c58 | 260 | BSP_LCD_SetFont( &Font24 ); |
jimk3038 | 1:39992c325c58 | 261 | sprintf( str, "%5.1f%s ", val, units ); |
jimk3038 | 1:39992c325c58 | 262 | lcd.DisplayStringAt( 0, y+30, (uint8_t *)str, RIGHT_MODE ); |
jimk3038 | 1:39992c325c58 | 263 | |
jimk3038 | 1:39992c325c58 | 264 | //p.x=0; p.y=y; |
jimk3038 | 1:39992c325c58 | 265 | //p.width=239; p.height=55; |
jimk3038 | 1:39992c325c58 | 266 | //myDrawRect( lcd, p, LCD_COLOR_WHITE ); |
jimk3038 | 1:39992c325c58 | 267 | } |
jimk3038 | 1:39992c325c58 | 268 | |
jimk3038 | 1:39992c325c58 | 269 | // Helper fuction to fill a rect given a lcd handle and a box struct. |
jimk3038 | 1:39992c325c58 | 270 | // ============================================================================ |
jimk3038 | 1:39992c325c58 | 271 | void myFillRect( LCD_DISCO_F429ZI lcd, box b ) { |
jimk3038 | 1:39992c325c58 | 272 | lcd.FillRect( b.x, b.y, b.width, b.height ); |
jimk3038 | 1:39992c325c58 | 273 | } |
jimk3038 | 1:39992c325c58 | 274 | |
jimk3038 | 1:39992c325c58 | 275 | // ============================================================================ |
jimk3038 | 1:39992c325c58 | 276 | void myDrawRect( LCD_DISCO_F429ZI lcd, box b, uint32_t color ) { |
jimk3038 | 1:39992c325c58 | 277 | uint32_t tmpColor = lcd.GetTextColor(); // Save current color. |
jimk3038 | 1:39992c325c58 | 278 | |
jimk3038 | 1:39992c325c58 | 279 | lcd.SetTextColor( color ); |
jimk3038 | 1:39992c325c58 | 280 | lcd.DrawRect( b.x, b.y, b.width, b.height ); |
jimk3038 | 1:39992c325c58 | 281 | // Draw an inner box to make the line 2 pixels wide. |
jimk3038 | 1:39992c325c58 | 282 | lcd.DrawRect( b.x+1, b.y+1, b.width-2, b.height-2 ); |
jimk3038 | 1:39992c325c58 | 283 | |
jimk3038 | 1:39992c325c58 | 284 | lcd.SetTextColor( tmpColor ); // Restore original color. |
jimk3038 | 1:39992c325c58 | 285 | } |
jimk3038 | 1:39992c325c58 | 286 | |
jimk3038 | 1:39992c325c58 | 287 | |
jimk3038 | 1:39992c325c58 | 288 | // Return true if x,y is within bounding box struct. |
jimk3038 | 1:39992c325c58 | 289 | // ============================================================================ |
jimk3038 | 1:39992c325c58 | 290 | bool testTouch( uint16_t x, uint16_t y, box b ) { |
jimk3038 | 1:39992c325c58 | 291 | |
jimk3038 | 1:39992c325c58 | 292 | if ( (x <= b.x) || (x >= (b.x+b.width)) ) return false; |
jimk3038 | 1:39992c325c58 | 293 | if ( (y <= b.y) || (y >= (b.y+b.height)) ) return false; |
jimk3038 | 1:39992c325c58 | 294 | return true; |
jimk3038 | 1:39992c325c58 | 295 | } |
jimk3038 | 1:39992c325c58 | 296 | |
jimk3038 | 1:39992c325c58 | 297 | // Update the param X/Y values and return true if new touch values. |
jimk3038 | 1:39992c325c58 | 298 | // ============================================================================ |
jimk3038 | 1:39992c325c58 | 299 | bool tsPress( uint16_t* xx, uint16_t* yy ) { |
jimk3038 | 1:39992c325c58 | 300 | TS_StateTypeDef TS_State; |
jimk3038 | 1:39992c325c58 | 301 | static bool flgTouch=true; |
jimk3038 | 1:39992c325c58 | 302 | static uint16_t x=0, y=0; |
jimk3038 | 1:39992c325c58 | 303 | |
jimk3038 | 1:39992c325c58 | 304 | tsTimer.start(); |
jimk3038 | 1:39992c325c58 | 305 | |
jimk3038 | 1:39992c325c58 | 306 | ts.GetState(&TS_State); |
jimk3038 | 1:39992c325c58 | 307 | if ( TS_State.TouchDetected ) { |
jimk3038 | 1:39992c325c58 | 308 | x = TS_State.X; |
jimk3038 | 1:39992c325c58 | 309 | y = TS_State.Y; |
jimk3038 | 1:39992c325c58 | 310 | printf("* x=%d y=%d\n", x, y); |
jimk3038 | 1:39992c325c58 | 311 | tsTimer.reset(); // Reset on new touch. |
jimk3038 | 1:39992c325c58 | 312 | flgTouch = true; // Set flag on new touch. |
jimk3038 | 1:39992c325c58 | 313 | } |
jimk3038 | 1:39992c325c58 | 314 | if ( flgTouch && (tsTimer.read_ms() > 250) ) { |
jimk3038 | 1:39992c325c58 | 315 | printf(" x=%d y=%d\n", x, y); |
jimk3038 | 1:39992c325c58 | 316 | flgTouch = false; |
jimk3038 | 1:39992c325c58 | 317 | } |
jimk3038 | 1:39992c325c58 | 318 | |
jimk3038 | 1:39992c325c58 | 319 | *xx = x; *yy = y; |
jimk3038 | 1:39992c325c58 | 320 | return flgTouch; // Return true on touch. |
jimk3038 | 1:39992c325c58 | 321 | } |
jimk3038 | 1:39992c325c58 | 322 | |
jimk3038 | 1:39992c325c58 | 323 | static void SystemClock_Config(void) |
jimk3038 | 1:39992c325c58 | 324 | { |
jimk3038 | 1:39992c325c58 | 325 | RCC_ClkInitTypeDef RCC_ClkInitStruct; |
jimk3038 | 1:39992c325c58 | 326 | RCC_OscInitTypeDef RCC_OscInitStruct; |
jimk3038 | 1:39992c325c58 | 327 | |
jimk3038 | 1:39992c325c58 | 328 | /* Enable Power Control clock */ |
jimk3038 | 1:39992c325c58 | 329 | __PWR_CLK_ENABLE(); |
jimk3038 | 1:39992c325c58 | 330 | |
jimk3038 | 1:39992c325c58 | 331 | /* The voltage scaling allows optimizing the power consumption when the device is |
jimk3038 | 1:39992c325c58 | 332 | clocked below the maximum system frequency, to update the voltage scaling value |
jimk3038 | 1:39992c325c58 | 333 | regarding system frequency refer to product datasheet. */ |
jimk3038 | 1:39992c325c58 | 334 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
jimk3038 | 1:39992c325c58 | 335 | |
jimk3038 | 1:39992c325c58 | 336 | /* Enable HSE Oscillator and activate PLL with HSE as source */ |
jimk3038 | 1:39992c325c58 | 337 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
jimk3038 | 1:39992c325c58 | 338 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
jimk3038 | 1:39992c325c58 | 339 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
jimk3038 | 1:39992c325c58 | 340 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
jimk3038 | 1:39992c325c58 | 341 | RCC_OscInitStruct.PLL.PLLM = 8; |
jimk3038 | 1:39992c325c58 | 342 | RCC_OscInitStruct.PLL.PLLN = 336; |
jimk3038 | 1:39992c325c58 | 343 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; |
jimk3038 | 1:39992c325c58 | 344 | RCC_OscInitStruct.PLL.PLLQ = 7; |
jimk3038 | 1:39992c325c58 | 345 | HAL_RCC_OscConfig(&RCC_OscInitStruct); |
jimk3038 | 1:39992c325c58 | 346 | |
jimk3038 | 1:39992c325c58 | 347 | /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
jimk3038 | 1:39992c325c58 | 348 | clocks dividers */ |
jimk3038 | 1:39992c325c58 | 349 | RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); |
jimk3038 | 1:39992c325c58 | 350 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
jimk3038 | 1:39992c325c58 | 351 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
jimk3038 | 1:39992c325c58 | 352 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; |
jimk3038 | 1:39992c325c58 | 353 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; |
jimk3038 | 1:39992c325c58 | 354 | HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5); |
jimk3038 | 1:39992c325c58 | 355 | } |