コード例 #1
0
ファイル: st7735.c プロジェクト: pal73/fat470
void lcdDrawVLine(uint16_t x, uint16_t y0, uint16_t y1, uint16_t color)
{
  // Allows for slightly better performance than setting individual pixels
  uint16_t y, pixels;

  if (y1 < y0)
  {
    // Switch y1 and y0
    y = y1;
    y1 = y0;
    y0 = y;
  }

  // Check limits
  if (y1 >= lcdGetHeight())
  {
    y1 = lcdGetHeight() - 1;
  }
  if (y0 >= lcdGetHeight())
  {
    y0 = lcdGetHeight() - 1;
  }

  st7735SetAddrWindow(x, y0, x, lcdGetHeight());
  st7735WriteCmd(ST7735_RAMWR);  // write to RAM
  for (pixels = 0; pixels < y1 - y0 + 1; pixels++)
  {
    st7735WriteData(color >> 8);  
    st7735WriteData(color);
  }
  st7735WriteCmd(ST7735_NOP);
}
コード例 #2
0
ファイル: touchscreen.c プロジェクト: fabienroyer/NetduinoGo
void tsCalibrate(void)
{
  tsTouchData_t data;

  /* --------------- Welcome Screen --------------- */
  data = tsRenderCalibrationScreen(lcdGetWidth() / 2, lcdGetHeight() / 2, 5);

  /* ----------------- First Dot ------------------ */
  // 10% over and 10% down
  data = tsRenderCalibrationScreen(lcdGetWidth() / 10, lcdGetHeight() / 10, 5);
  _tsLCDPoints[0].x = lcdGetWidth() / 10;
  _tsLCDPoints[0].y = lcdGetHeight() / 10;
  _tsTSPoints[0].x = data.xraw;
  _tsTSPoints[0].y = data.yraw;

  /* ---------------- Second Dot ------------------ */
  // 50% over and 90% down
  data = tsRenderCalibrationScreen(lcdGetWidth() / 2, lcdGetHeight() - lcdGetHeight() / 10, 5);
  _tsLCDPoints[1].x = lcdGetWidth() / 2;
  _tsLCDPoints[1].y = lcdGetHeight() - lcdGetHeight() / 10;
  _tsTSPoints[1].x = data.xraw;
  _tsTSPoints[1].y = data.yraw;

  /* ---------------- Third Dot ------------------- */
  // 90% over and 50% down
  data = tsRenderCalibrationScreen(lcdGetWidth() - lcdGetWidth() / 10, lcdGetHeight() / 2, 5);
  _tsLCDPoints[2].x = lcdGetWidth() - lcdGetWidth() / 10;
  _tsLCDPoints[2].y = lcdGetHeight() / 2;
  _tsTSPoints[2].x = data.xraw;
  _tsTSPoints[2].y = data.yraw;

  // Do matrix calculations for calibration and store to EEPROM
  setCalibrationMatrix(&_tsLCDPoints[0], &_tsTSPoints[0], &_tsMatrix);
}
コード例 #3
0
ファイル: st7735.c プロジェクト: pal73/fat470
void lcdFillRGB(uint16_t color)
{
  uint8_t x, y;
  st7735SetAddrWindow(0, 0, lcdGetWidth() - 1, lcdGetHeight() - 1);
  st7735WriteCmd(ST7735_RAMWR);  // write to RAM
  for (x=0; x < lcdGetWidth(); x++) 
  {
    for (y=0; y < lcdGetHeight(); y++) 
    {
      st7735WriteData(color >> 8);    
      st7735WriteData(color);    
    }
  }
  st7735WriteCmd(ST7735_NOP);
}
コード例 #4
0
ファイル: touchscreen.c プロジェクト: fabienroyer/NetduinoGo
int getDisplayPoint( tsPoint_t * displayPtr, tsPoint_t * screenPtr, tsMatrix_t * matrixPtr ) {
  int  retValue = 0 ;

  if( matrixPtr->Divider != 0 ) {
    displayPtr->x = ( (matrixPtr->An * screenPtr->x) +
                      (matrixPtr->Bn * screenPtr->y) +
                       matrixPtr->Cn
                    ) / matrixPtr->Divider ;

    displayPtr->y = ( (matrixPtr->Dn * screenPtr->x) +
                      (matrixPtr->En * screenPtr->y) +
                       matrixPtr->Fn
                    ) / matrixPtr->Divider ;
  } else {
    retValue = -1 ;
  }

  // Adjust value if the screen is in landscape mode
  lcdOrientation_t orientation;
  orientation = lcdGetOrientation();
  if (orientation == LCD_ORIENTATION_LANDSCAPE) {
      uint32_t oldx, oldy;
      oldx = displayPtr->x;
      oldy = displayPtr->y;
      displayPtr->x = oldy;
      displayPtr->y = lcdGetHeight() - oldx;
  }

  return(retValue);
}
コード例 #5
0
ファイル: cmd_sysinfo.c プロジェクト: pal73/fat470
void cmd_sysinfo(uint8_t argc, char **argv)
{
  IAP_return_t iap_return;

  printf("%-25s : %d.%d MHz %s", "System Clock", CFG_CPU_CCLK / 1000000, CFG_CPU_CCLK % 1000000, CFG_PRINTF_NEWLINE);
  printf("%-25s : v%d.%d.%d %s", "Firmware", CFG_FIRMWARE_VERSION_MAJOR, CFG_FIRMWARE_VERSION_MINOR, CFG_FIRMWARE_VERSION_REVISION, CFG_PRINTF_NEWLINE);

  // 128-bit MCU Serial Number
  iap_return = iapReadSerialNumber();
  if(iap_return.ReturnCode == 0)
  {
    printf("%-25s : %08X %08X %08X %08X %s", "Serial Number", iap_return.Result[0],iap_return.Result[1],iap_return.Result[2],iap_return.Result[3], CFG_PRINTF_NEWLINE);
  }

  // CLI and buffer Settings
  #ifdef CFG_INTERFACE
    printf("%-25s : %d bytes %s", "Max CLI Command", CFG_INTERFACE_MAXMSGSIZE, CFG_PRINTF_NEWLINE);
  #endif

  #ifdef CFG_PRINTF_UART
    uart_pcb_t *pcb = uartGetPCB();
    printf("%-25s : %d %s", "UART Baud Rate", pcb->baudrate, CFG_PRINTF_NEWLINE);
  #endif

  // TFT LCD Settings (if CFG_TFTLCD enabled)
  #ifdef CFG_TFTLCD
    printf("%-25s : %d %s", "LCD Width", (int)lcdGetWidth(), CFG_PRINTF_NEWLINE);
    printf("%-25s : %d %s", "LCD Height", (int)lcdGetHeight(), CFG_PRINTF_NEWLINE);
  #endif

  // Wireless Settings (if CFG_CHIBI enabled)
  #ifdef CFG_CHIBI
    chb_pcb_t *pcb = chb_get_pcb();
    printf("%-25s : %s %s", "Wireless", "AT86RF212", CFG_PRINTF_NEWLINE);
    printf("%-25s : 0x%04X %s", "802.15.4 PAN ID", CFG_CHIBI_PANID, CFG_PRINTF_NEWLINE);
    printf("%-25s : 0x%04X %s", "802.15.4 Node Address", pcb->src_addr, CFG_PRINTF_NEWLINE);
    printf("%-25s : %d %s", "802.15.4 Channel", CFG_CHIBI_CHANNEL, CFG_PRINTF_NEWLINE);
  #endif

  // System Uptime (based on systick timer)
  printf("%-25s : %u s %s", "System Uptime", (unsigned int)systickGetSecondsActive(), CFG_PRINTF_NEWLINE);

  // System Temperature (if LM75B Present)
  #ifdef CFG_LM75B
    int32_t temp = 0;
    lm75bGetTemperature(&temp);
    temp *= 125;
    printf("%-25s : %d.%d C %s", "Temperature", temp / 1000, temp % 1000, CFG_PRINTF_NEWLINE);
  #endif

  #ifdef CFG_SDCARD
    printf("%-25s : %s %s", "SD Card Present", gpioGetValue(CFG_SDCARD_CDPORT, CFG_SDCARD_CDPIN) ? "True" : "False", CFG_PRINTF_NEWLINE);
  #endif
}
コード例 #6
0
void tsCalibrate(void)
{
  tsTouchData_t data;

  /* --------------- Welcome Screen --------------- */
  data = tsRenderCalibrationScreen(lcdGetWidth() / 2, lcdGetHeight() / 2, 5);
  systickDelay(250);

  /* ----------------- First Dot ------------------ */
  // 10% over and 10% down
  data = tsRenderCalibrationScreen(lcdGetWidth() / 10, lcdGetHeight() / 10, 5);
  _tsLCDPoints[0].x = lcdGetWidth() / 10;
  _tsLCDPoints[0].y = lcdGetHeight() / 10;
  _tsTSPoints[0].x = data.xraw;
  _tsTSPoints[0].y = data.yraw;
  printf("Point 1 - LCD X:%04d Y:%04d TS X:%04d Y:%04d \r\n", 
        (int)_tsLCDPoints[0].x, (int)_tsLCDPoints[0].y, (int)_tsTSPoints[0].x, (int)_tsTSPoints[0].y);
  systickDelay(250);

  /* ---------------- Second Dot ------------------ */
  // 50% over and 90% down
  data = tsRenderCalibrationScreen(lcdGetWidth() / 2, lcdGetHeight() - lcdGetHeight() / 10, 5);
  _tsLCDPoints[1].x = lcdGetWidth() / 2;
  _tsLCDPoints[1].y = lcdGetHeight() - lcdGetHeight() / 10;
  _tsTSPoints[1].x = data.xraw;
  _tsTSPoints[1].y = data.yraw;
  printf("Point 2 - LCD X:%04d Y:%04d TS X:%04d Y:%04d \r\n", 
       (int)_tsLCDPoints[1].x, (int)_tsLCDPoints[1].y, (int)_tsTSPoints[1].x, (int)_tsTSPoints[1].y);
  systickDelay(250);

  /* ---------------- Third Dot ------------------- */
  // 90% over and 50% down
  data = tsRenderCalibrationScreen(lcdGetWidth() - lcdGetWidth() / 10, lcdGetHeight() / 2, 5);
  _tsLCDPoints[2].x = lcdGetWidth() - lcdGetWidth() / 10;
  _tsLCDPoints[2].y = lcdGetHeight() / 2;
  _tsTSPoints[2].x = data.xraw;
  _tsTSPoints[2].y = data.yraw;
  printf("Point 3 - LCD X:%04d Y:%04d TS X:%04d Y:%04d \r\n", 
        (int)_tsLCDPoints[2].x, (int)_tsLCDPoints[2].y, (int)_tsTSPoints[2].x, (int)_tsTSPoints[2].y);
  systickDelay(250);

  // Do matrix calculations for calibration and store to EEPROM
  setCalibrationMatrix(&_tsLCDPoints[0], &_tsTSPoints[0], &_tsMatrix);
}
コード例 #7
0
ファイル: main.c プロジェクト: Anubirux/ChibiOS-LCD-Driver
int main(void) {
	halInit();
	chSysInit();
	
	lcdInit(&GLCDD1);
	lcdClear(Black);
	lcdDrawString(100, 100, "Hello World", White, Black);

	lcdMoveCursor(10,10,White, Black);
	chprintf((BaseSequentialStream *)&GLCDD1, "chTimeNow: %d", chTimeNow());

	lcdDrawCircle(150, 150, 10, filled, Green);
	lcdDrawLine(0, 0, lcdGetWidth(), lcdGetHeight(), Yellow);

	while (TRUE) {
		
		chThdSleepMilliseconds(200);	
	}

	return 0;
}
コード例 #8
0
int getDisplayPoint( tsPoint_t * displayPtr, tsPoint_t * screenPtr, tsMatrix_t * matrixPtr )
{
  int  retValue = TS_ERROR_NONE ;
  
  if( matrixPtr->Divider != 0 )
  {
    displayPtr->x = ( (matrixPtr->An * screenPtr->x) + 
                      (matrixPtr->Bn * screenPtr->y) + 
                       matrixPtr->Cn 
                    ) / matrixPtr->Divider ;

    displayPtr->y = ( (matrixPtr->Dn * screenPtr->x) + 
                      (matrixPtr->En * screenPtr->y) + 
                       matrixPtr->Fn 
                    ) / matrixPtr->Divider ;
  }
  else
  {
    // ToDo: Default values required or you can never read LCD position!
    // return TS_ERROR_NOTCALIBRATED;
    return -1;
  }

  // Adjust value if the screen is in landscape mode
  lcdOrientation_t orientation;
  orientation = lcdGetOrientation();
  if (orientation == LCD_ORIENTATION_LANDSCAPE)
  {
      uint32_t oldx, oldy;
      oldx = displayPtr->x;
      oldy = displayPtr->y;
      displayPtr->x = oldy;
      displayPtr->y = lcdGetHeight() - oldx;
  }
  
  return( retValue ) ;
}
コード例 #9
0
ファイル: alphanumeric.c プロジェクト: pal73/fat470
char* alphaShowDialogue(void)
{
  char result;

  /* These need to be instantiated here since the width and height of 
     the lcd is retrieved dynamically depending on screen orientation */
  alphaBtnX[0] = ALPHA_COL1_LEFT;
  alphaBtnX[1] = ALPHA_COL2_LEFT;
  alphaBtnX[2] = ALPHA_COL3_LEFT;
  alphaBtnX[3] = ALPHA_COL4_LEFT;
  alphaBtnX[4] = ALPHA_COL5_LEFT;
  alphaBtnY[0] = ALPHA_ROW1_TOP;
  alphaBtnY[1] = ALPHA_ROW2_TOP;
  alphaBtnY[2] = ALPHA_ROW3_TOP;
  alphaBtnY[3] = ALPHA_ROW4_TOP;
  alphaBtnY[4] = ALPHA_ROW5_TOP;
  alphaBtnY[5] = ALPHA_ROW6_TOP;

  /* Initialise the string buffer */
  memset(&alphaString[0], 0, sizeof(alphaString));
  alphaString_ptr = alphaString;
  alphaPage = 0;

  /* Draw the background and render the buttons */
  drawFill(COLOR_WHITE);
  drawRectangleFilled(0, ALPHA_KEYPAD_TOP - ALPHA_BTN_SPACING, lcdGetWidth() - 1, lcdGetHeight() - 1, COLOR_DARKGRAY);
  drawLine(0, (ALPHA_KEYPAD_TOP - ALPHA_BTN_SPACING) + 1, lcdGetWidth() - 1, (ALPHA_KEYPAD_TOP - ALPHA_BTN_SPACING) + 1, COLOR_LIGHTGRAY);
  alphaRefreshScreen();

  /* Capture results until the 'OK' button is pressed */
  while(1)
  {
    result = alphaHandleTouchEvent();
    if (result == '>') return (char *)&alphaString;
  }
}
コード例 #10
0
ファイル: bmp.c プロジェクト: tengzhang8/olyMEMS
bmp_error_t bmpParseBitmap(uint16_t x, uint16_t y, FIL file)
{
  UINT              bytesRead;
  bmp_header_t      header;
  bmp_infoheader_t  infoHeader;

  // Read the file header
  // ToDo: Optimise this to read buffer once and parse it
  f_read(&file, &header.type, sizeof(header.type), &bytesRead);
  f_read(&file, &header.size, sizeof(header.size), &bytesRead);
  f_read(&file, &header.reserved1, sizeof(header.reserved1), &bytesRead);
  f_read(&file, &header.reserved2, sizeof(header.reserved2), &bytesRead);
  f_read(&file, &header.offset, sizeof(header.offset), &bytesRead);

  // Make sure this is a bitmap (first two bytes = 'BM' or 0x4D42 on little-endian systems)
  if (header.type != 0x4D42) return BMP_ERROR_NOTABITMAP;

  // Read the info header
  // ToDo: Optimise this to read buffer once and parse it
  f_read(&file, &infoHeader.size, sizeof(infoHeader.size), &bytesRead);
  f_read(&file, &infoHeader.width, sizeof(infoHeader.width), &bytesRead);
  f_read(&file, &infoHeader.height, sizeof(infoHeader.height), &bytesRead);
  f_read(&file, &infoHeader.planes, sizeof(infoHeader.planes), &bytesRead);
  f_read(&file, &infoHeader.bits, sizeof(infoHeader.bits), &bytesRead);
  f_read(&file, &infoHeader.compression, sizeof(infoHeader.compression), &bytesRead);
  f_read(&file, &infoHeader.imagesize, sizeof(infoHeader.imagesize), &bytesRead);
  f_read(&file, &infoHeader.xresolution, sizeof(infoHeader.xresolution), &bytesRead);
  f_read(&file, &infoHeader.yresolution, sizeof(infoHeader.yresolution), &bytesRead);
  f_read(&file, &infoHeader.ncolours, sizeof(infoHeader.ncolours), &bytesRead);
  f_read(&file, &infoHeader.importantcolours, sizeof(infoHeader.importantcolours), &bytesRead);

  // Make sure that this is a 24-bit image
  if (infoHeader.bits != 24) 
    return BMP_ERROR_INVALIDBITDEPTH;

  // Check image dimensions
  if ((infoHeader.width > lcdGetWidth()) | (infoHeader.height > lcdGetHeight()))
    return BMP_ERROR_INVALIDDIMENSIONS;

  // Make sure image is not compressed
  if (infoHeader.compression != BMP_COMPRESSION_NONE) 
    return BMP_ERROR_COMPRESSEDDATA;

  // Read 24-bit image data
  uint32_t px, py;
  FRESULT res;
  uint8_t buffer[infoHeader.width * 3];
  for (py = infoHeader.height; py > 0; py--)
  {
    // Read one row at a time
    res = f_read(&file, &buffer, infoHeader.width * 3, &bytesRead);
    if (res || bytesRead == 0)
    {
      // Error or EOF
      return BMP_ERROR_PREMATUREEOF;
    }
    for (px = 0; px < infoHeader.width; px++)
    {
      // Render pixel
      // ToDo: This is a brutally slow way of rendering bitmaps ...
      //        update to pass one row of data at a time
      drawPixel(x + px, y + py - 1, drawRGB24toRGB565(buffer[(px * 3) + 2], buffer[(px * 3) + 1], buffer[(px * 3)]));
    }
  }

  return BMP_ERROR_NONE;
}
コード例 #11
0
ファイル: cmd_sysinfo.c プロジェクト: Miceuz/LPC1343CodeBase
void cmd_sysinfo(uint8_t argc, char **argv)
{
  IAP_return_t iap_return;

  /* Note: Certain values are only reported if CFG_INTERFACE_LONGSYSINFO
     is set to 1 in projectconfig.h.  These extra values are more useful
     for debugging than real-world use, so there's no point wasiting
     flash space storing the code for them */

  printf("%-25s : %d.%d.%d %s", "Firmware", CFG_FIRMWARE_VERSION_MAJOR, CFG_FIRMWARE_VERSION_MINOR, CFG_FIRMWARE_VERSION_REVISION, CFG_PRINTF_NEWLINE);
  printf("%-25s : %d.%d MHz %s", "System Clock", CFG_CPU_CCLK / 1000000, CFG_CPU_CCLK % 1000000, CFG_PRINTF_NEWLINE);

  // System Uptime (based on systick timer)
  printf("%-25s : %u s %s", "System Uptime", (unsigned int)systickGetSecondsActive(), CFG_PRINTF_NEWLINE);

  // 128-bit MCU Serial Number
  iap_return = iapReadSerialNumber();
  if(iap_return.ReturnCode == 0)
  {
    printf("%-25s : %08X %08X %08X %08X %s", "Serial Number", iap_return.Result[0],iap_return.Result[1],iap_return.Result[2],iap_return.Result[3], CFG_PRINTF_NEWLINE);
  }

  #if CFG_INTERFACE_LONGSYSINFO
    #ifdef CFG_USBCDC
      printf("%-25s : %d ms %s", "USB Init Timeout", CFG_USBCDC_INITTIMEOUT, CFG_PRINTF_NEWLINE);
    #endif
  #endif

  // CLI and buffer Settings
  #if CFG_INTERFACE_LONGSYSINFO
    printf("%-25s : %d bytes %s", "CLI Max Command Size", CFG_INTERFACE_MAXMSGSIZE, CFG_PRINTF_NEWLINE);
    printf("%-25s : %s %s", "CLI IRQ Enabled", CFG_INTERFACE_ENABLEIRQ ? "True" : "False", CFG_PRINTF_NEWLINE);
    #if CFG_INTERFACE_ENABLEIRQ
      printf("%-25s : %d.%d %s", "CLI IRQ Location", CFG_INTERFACE_IRQPORT, CFG_INTERFACE_IRQPIN, CFG_PRINTF_NEWLINE);
    #endif
  #endif

  #if CFG_INTERFACE_LONGSYSINFO
    #ifdef CFG_I2CEEPROM
      printf("%-25s : %d bytes %s", "EEPROM Size", CFG_I2CEEPROM_SIZE, CFG_PRINTF_NEWLINE);
    #endif
  #endif

  #ifdef CFG_SDCARD
    printf("%-25s : %s %s", "SD Card Present", gpioGetValue(CFG_SDCARD_CDPORT, CFG_SDCARD_CDPIN) ? "True" : "False", CFG_PRINTF_NEWLINE);
    #if CFG_INTERFACE_LONGSYSINFO
      printf("%-25s : %s %s", "FAT File System", CFG_SDCARD_READONLY ? "Read Only" : "Read/Write", CFG_PRINTF_NEWLINE);
    #endif
  #endif

  #ifdef CFG_PRINTF_UART
    uart_pcb_t *pcb = uartGetPCB();
    printf("%-25s : %u %s", "UART Baud Rate", (unsigned int)(pcb->baudrate), CFG_PRINTF_NEWLINE);
  #endif

  // TFT LCD Settings (if CFG_TFTLCD enabled)
  #ifdef CFG_TFTLCD
    printf("%-25s : %d %s", "LCD Width", (int)lcdGetWidth(), CFG_PRINTF_NEWLINE);
    printf("%-25s : %d %s", "LCD Height", (int)lcdGetHeight(), CFG_PRINTF_NEWLINE);
    #if CFG_INTERFACE_LONGSYSINFO
      printf("%-25s : %04X %s", "LCD Controller ID", (unsigned short)lcdGetControllerID(), CFG_PRINTF_NEWLINE);
      printf("%-25s : %s %s", "LCD Small Fonts", CFG_TFTLCD_INCLUDESMALLFONTS == 1 ? "True" : "False", CFG_PRINTF_NEWLINE);
      printf("%-25s : %s %s", "LCD AA Fonts", CFG_TFTLCD_USEAAFONTS == 1 ? "True" : "False", CFG_PRINTF_NEWLINE);
      lcdProperties_t lcdprops = lcdGetProperties();
      printf("%-25s : %s %s", "Touch Screen", lcdprops.touchscreen ? "True" : "False", CFG_PRINTF_NEWLINE);
      if (lcdprops.touchscreen)
      {
        printf("%-25s : %s %s", "Touch Screen Calibrated", eepromReadU8(CFG_EEPROM_TOUCHSCREEN_CALIBRATED) == 1 ? "True" : "False", CFG_PRINTF_NEWLINE);
        printf("%-25s : %d %s", "Touch Screen Threshold", CFG_TFTLCD_TS_DEFAULTTHRESHOLD, CFG_PRINTF_NEWLINE);
      }
    #endif
  #endif

  // Wireless Settings (if CFG_CHIBI enabled)
  #ifdef CFG_CHIBI
    chb_pcb_t *pcb = chb_get_pcb();
    printf("%-25s : %s %s", "Wireless", "AT86RF212", CFG_PRINTF_NEWLINE);
    printf("%-25s : 0x%04X %s", "802.15.4 PAN ID", CFG_CHIBI_PANID, CFG_PRINTF_NEWLINE);
    printf("%-25s : 0x%04X %s", "802.15.4 Node Address", pcb->src_addr, CFG_PRINTF_NEWLINE);
    printf("%-25s : %d %s", "802.15.4 Channel", CFG_CHIBI_CHANNEL, CFG_PRINTF_NEWLINE);
  #endif

  // System Temperature (if LM75B Present)
  #ifdef CFG_LM75B
    int32_t temp = 0;
    lm75bGetTemperature(&temp);
    temp *= 125;
    printf("%-25s : %d.%d C %s", "Temperature", temp / 1000, temp % 1000, CFG_PRINTF_NEWLINE);
  #endif

  // ADC Averaging
  #if CFG_INTERFACE_LONGSYSINFO
    printf("%-25s : %s %s", "ADC Averaging", ADC_AVERAGING_ENABLE ? "True" : "False", CFG_PRINTF_NEWLINE);
    #if ADC_AVERAGING_ENABLE
      printf("%-25s : %d %s", "ADC Averaging Samples", ADC_AVERAGING_SAMPLES, CFG_PRINTF_NEWLINE);
    #endif
  #endif

  // Debug LED
  #if CFG_INTERFACE_LONGSYSINFO
    printf("%-25s : %d.%d %s", "LED Location", CFG_LED_PORT, CFG_LED_PIN, CFG_PRINTF_NEWLINE);
  #endif
}
コード例 #12
0
ファイル: bmp.c プロジェクト: Miceuz/LPC1343CodeBase
bmp_error_t bmpSaveScreenshot(const char* filename)
{
  DSTATUS stat;
  bmp_error_t error = BMP_ERROR_NONE;
  bmp_header_t header;
  bmp_infoheader_t infoHeader;
  uint32_t lcdWidth, lcdHeight, x, y, bgra32;
  UINT bytesWritten;
  uint16_t rgb565, eof;
  uint8_t r, g, b;

  // Create a new file (Crossworks only)
  stat = disk_initialize(0);
  if (stat & STA_NOINIT) 
  {
    return BMP_ERROR_SDINITFAIL;
  }
  if (stat & STA_NODISK) 
  {
    return BMP_ERROR_SDINITFAIL;
  }
  if (stat == 0)
  {
    // SD card sucessfully initialised
    DSTATUS stat;
    DWORD p2;
    WORD w1;
    BYTE res, b1;
    DIR dir; 
    // Try to mount drive
    res = f_mount(0, &Fatfs[0]);
    if (res != FR_OK) 
    {
      return BMP_ERROR_SDINITFAIL;
    }
    if (res == FR_OK)
    {
      // Create a file (overwriting any existing file!)
      if(f_open(&bmpSDFile, filename, FA_READ | FA_WRITE | FA_CREATE_ALWAYS)!=FR_OK) 
      {  
        return BMP_ERROR_UNABLETOCREATEFILE; 
      }
    }
  }

  lcdWidth = lcdGetWidth();
  lcdHeight = lcdGetHeight();

  // Create header
  header.type = 0x4d42;   // 'BM'
  header.size = (lcdWidth * lcdHeight * 3) + sizeof(header) + sizeof(infoHeader);   // File size in bytes
  header.reserved1 = 0;
  header.reserved2 = 0;
  header.offset = 0x36;   // Offset in bytes to the image data
  
  // Create infoheader
  infoHeader.size = sizeof(infoHeader);
  infoHeader.width = lcdWidth;
  infoHeader.height = lcdHeight;
  infoHeader.planes = 1;
  infoHeader.bits = 24;
  infoHeader.compression = BMP_COMPRESSION_NONE;
  infoHeader.imagesize = (lcdWidth * lcdHeight * 3) + 2;  // 3 bytes per pixel + 2 bytes for EOF
  infoHeader.xresolution = 0x0B12;
  infoHeader.yresolution = 0x0B12;
  infoHeader.ncolours = 0;
  infoHeader.importantcolours = 0;

  // Write header to disk
  f_write(&bmpSDFile, &header.type, sizeof(header.type), &bytesWritten);
  f_write(&bmpSDFile, &header.size, sizeof(header.size), &bytesWritten);
  f_write(&bmpSDFile, &header.reserved1, sizeof(header.reserved1), &bytesWritten);
  f_write(&bmpSDFile, &header.reserved2, sizeof(header.reserved2), &bytesWritten);
  f_write(&bmpSDFile, &header.offset, sizeof(header.offset), &bytesWritten);
  f_write(&bmpSDFile, &infoHeader.size, sizeof(infoHeader.size), &bytesWritten);
  f_write(&bmpSDFile, &infoHeader.width, sizeof(infoHeader.width), &bytesWritten);
  f_write(&bmpSDFile, &infoHeader.height, sizeof(infoHeader.height), &bytesWritten);
  f_write(&bmpSDFile, &infoHeader.planes, sizeof(infoHeader.planes), &bytesWritten);
  f_write(&bmpSDFile, &infoHeader.bits, sizeof(infoHeader.bits), &bytesWritten);
  f_write(&bmpSDFile, &infoHeader.compression, sizeof(infoHeader.compression), &bytesWritten);
  f_write(&bmpSDFile, &infoHeader.imagesize, sizeof(infoHeader.imagesize), &bytesWritten);
  f_write(&bmpSDFile, &infoHeader.xresolution, sizeof(infoHeader.xresolution), &bytesWritten);
  f_write(&bmpSDFile, &infoHeader.yresolution, sizeof(infoHeader.yresolution), &bytesWritten);
  f_write(&bmpSDFile, &infoHeader.ncolours, sizeof(infoHeader.ncolours), &bytesWritten);
  f_write(&bmpSDFile, &infoHeader.importantcolours, sizeof(infoHeader.importantcolours), &bytesWritten);

  // Write image data to disk (starting from bottom row)
  for (y = lcdHeight; y != 0; y--)
  {
    for (x = 0; x < lcdWidth; x++)
    {
      rgb565 = lcdGetPixel(x, y - 1);               // Get RGB565 pixel
      bgra32 = colorsRGB565toBGRA32(rgb565);          // Convert RGB565 to 24-bit color
      r = (bgra32 & 0x00FF0000) >> 16;
      g = (bgra32 & 0x0000FF00) >> 8;
      b = (bgra32 & 0x000000FF);
      f_write(&bmpSDFile, &b, 1, &bytesWritten);    // Write RGB data
      f_write(&bmpSDFile, &g, 1, &bytesWritten);
      f_write(&bmpSDFile, &r, 1, &bytesWritten);
    }    
  }
  
  // Write EOF (2 bytes)
  eof = 0x0000;
  f_write(&bmpSDFile, &eof, 2, &bytesWritten);

  // Close the file
  f_close(&bmpSDFile);

  // Return OK signal
  return BMP_ERROR_NONE;
}
コード例 #13
0
ファイル: touchscreen.c プロジェクト: pal73/fat470
tsTouchError_t tsWaitForEvent(tsTouchData_t* data, uint32_t timeoutMS)
{
  if (!_tsInitialised) tsInit();

  uint32_t z1, z2;
  uint32_t xRaw1, xRaw2, yRaw1, yRaw2;
  z1 = z2 = 0;

  // Handle timeout if delay > 0 milliseconds
  if (timeoutMS)
  {
    uint32_t startTick = systickGetTicks();
    // Systick rollover may occur while waiting for timeout
    if (startTick > 0xFFFFFFFF - timeoutMS)
    {
      // Wait for timeout or touch event
      while (z2 < CFG_TFTLCD_TS_THRESHOLD)
      {
        // Throw alert if timeout delay has been passed
        if ((systickGetTicks() < startTick) && (systickGetTicks() >= (timeoutMS - (0xFFFFFFFF - startTick))))
        {
          return TS_ERROR_TIMEOUT;
        }      
        tsReadZ(&z1, &z2);
      }
    }
    // No systick rollover will occur ... calculate timeout the simple way
    else
    {
      // Wait in infinite loop
      while (z2 < CFG_TFTLCD_TS_THRESHOLD)
      {
        // Throw timeout if delay has been passed
        if ((systickGetTicks() - startTick) > timeoutMS)
        {
          return TS_ERROR_TIMEOUT;
        }
        tsReadZ(&z1, &z2);
      }
    }
  }
  // No timeout requested ... wait forever
  else
  {
    while (z2 < CFG_TFTLCD_TS_THRESHOLD)
    {
      tsReadZ(&z1, &z2);
    }
  }

  // Get raw conversion results
  // Each value is read twice and compared to avoid erroneous readings
  xRaw1 = tsReadY();    // X and Y are reversed
  xRaw2 = tsReadY();    // X and Y are reversed
  yRaw1 = tsReadX();    // X and Y are reverse
  yRaw2 = tsReadX();    // X and Y are reverse

  // If both read attempts aren't identical, return mismatch error
  if ((xRaw1 != xRaw2) || (yRaw1 != yRaw2))
  {
    return TS_ERROR_XYMISMATCH;
  }

  // Normalise X
  data->x = ((xRaw1 - _calibration.offsetLeft > TS_ADC_LIMIT ? 0 : xRaw1 - _calibration.offsetLeft) * 100) / _calibration.divisorX;
  if (data->x > lcdGetWidth() - 1) data->x = lcdGetWidth() - 1;

  // Normalise Y
  data->y = ((yRaw1 - _calibration.offsetTop > TS_ADC_LIMIT ? 0 : yRaw1 - _calibration.offsetTop) * 100) / _calibration.divisorY;
  if (data->y > lcdGetHeight() - 1) data->y = lcdGetHeight() - 1;

  // Indicate correct reading
  return TS_ERROR_NONE;
}
コード例 #14
0
ファイル: touchscreen.c プロジェクト: pal73/fat470
void tsCalibrate(void)
{
  lcdOrientation_t orientation;
  uint16_t right2, top2, left2, bottom2;
  bool passed = false;

  // Determine screen orientation before starting calibration
  orientation = lcdGetOrientation();

  /* -------------- Welcome Screen --------------- */
  tsRenderCalibrationScreen(lcdGetWidth() / 2, lcdGetHeight() / 2, 5);

  // Delay to avoid multiple touch events
  systickDelay(250);

  /* -------------- CALIBRATE TOP-LEFT --------------- */
  passed = false;
  while (!passed)
  {
    // Read X/Y depending on screen orientation
    tsRenderCalibrationScreen(3, 3, 5);
    _calibration.offsetLeft = orientation == LCD_ORIENTATION_LANDSCAPE ? tsReadY() : tsReadX();
    _calibration.offsetTop = orientation == LCD_ORIENTATION_LANDSCAPE ? tsReadX() : tsReadY();
  
    // Make sure values are in range
    if (_calibration.offsetLeft < TS_CALIBRATION_OUTOFRANGE && _calibration.offsetTop < TS_CALIBRATION_OUTOFRANGE)
      passed = true;
  }

  // Delay to avoid multiple touch events
  systickDelay(250);

  /* -------------- CALIBRATE BOTTOM-RIGHT  --------------- */
  passed = false;
  while (!passed)
  {
    tsRenderCalibrationScreen(lcdGetWidth() - 4, lcdGetHeight() - 4, 5);
  
    // Read X/Y depending on screen orientation
    _calibration.offsetRight = orientation == LCD_ORIENTATION_LANDSCAPE ? TS_ADC_LIMIT - tsReadY() : TS_ADC_LIMIT - tsReadX();
    _calibration.offsetBottom = orientation == LCD_ORIENTATION_LANDSCAPE ? TS_ADC_LIMIT - tsReadX() : TS_ADC_LIMIT - tsReadY();
  
    // Redo test if value is out of range
    if (_calibration.offsetRight < TS_CALIBRATION_OUTOFRANGE && _calibration.offsetBottom < TS_CALIBRATION_OUTOFRANGE)
      passed = true;
  }

  // Delay to avoid multiple touch events
  systickDelay(250);

  /* -------------- CALIBRATE TOP-RIGHT  --------------- */
  passed = false;
  while (!passed)
  {
    tsRenderCalibrationScreen(lcdGetWidth() - 4, 3, 5);
  
    if (orientation == LCD_ORIENTATION_LANDSCAPE)
    {
      right2 = TS_ADC_LIMIT - tsReadY();
      top2 = tsReadX();
    }
    else
    {
      right2 = tsReadX();
      top2 = TS_ADC_LIMIT - tsReadY();
    }
  
    // Redo test if value is out of range
    if (right2 < TS_CALIBRATION_OUTOFRANGE && top2 < TS_CALIBRATION_OUTOFRANGE)
      passed = true;  
  }

  // Average readings
  _calibration.offsetRight = (_calibration.offsetRight + right2) / 2;
  _calibration.offsetTop = (_calibration.offsetTop + top2) / 2;

  // Delay to avoid multiple touch events
  systickDelay(250);

  /* -------------- CALIBRATE BOTTOM-LEFT --------------- */
  passed = false;
  while (!passed)
  {
    tsRenderCalibrationScreen(3, lcdGetHeight() - 4, 5);
  
    if (orientation == LCD_ORIENTATION_LANDSCAPE)
    {
      left2 = tsReadY();
      bottom2 = TS_ADC_LIMIT - tsReadX();
    }
    else
    {
      left2 = TS_ADC_LIMIT - tsReadX();
      bottom2 = tsReadY();
    }
  
    // Redo test if value is out of range
    if (left2 < TS_CALIBRATION_OUTOFRANGE && bottom2 < TS_CALIBRATION_OUTOFRANGE)
      passed = true;
  }

  // Average readings
  _calibration.offsetLeft = (_calibration.offsetLeft + left2) / 2;
  _calibration.offsetBottom = (_calibration.offsetBottom + bottom2) / 2;

  // Delay to avoid multiple touch events
  systickDelay(250);

  _calibration.divisorX = ((TS_ADC_LIMIT - (_calibration.offsetLeft + _calibration.offsetRight)) * 100) / lcdGetWidth();
  _calibration.divisorY = ((TS_ADC_LIMIT - (_calibration.offsetTop + _calibration.offsetBottom)) * 100) / lcdGetHeight();

  /* -------------- Persist Data --------------- */
  // Persist data to EEPROM
  eepromWriteU16(CFG_EEPROM_TOUCHSCREEN_OFFSET_LEFT, _calibration.offsetLeft);
  eepromWriteU16(CFG_EEPROM_TOUCHSCREEN_OFFSET_RIGHT, _calibration.offsetRight);
  eepromWriteU16(CFG_EEPROM_TOUCHSCREEN_OFFSET_TOP, _calibration.offsetTop);
  eepromWriteU16(CFG_EEPROM_TOUCHSCREEN_OFFSET_BOT, _calibration.offsetBottom);
  eepromWriteU16(CFG_EEPROM_TOUCHSCREEN_OFFSET_DIVX, _calibration.divisorX);
  eepromWriteU16(CFG_EEPROM_TOUCHSCREEN_OFFSET_DIVY, _calibration.divisorY);
  eepromWriteU8(CFG_EEPROM_TOUCHSCREEN_CALIBRATED, 1);

  // Clear the screen
  drawFill(COLOR_BLACK);
}