diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d04a3a..bb9b6f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.0.5 (2025-01-15) + +## Bug Fixes + +- fix reset errors + ## 1.0.4 (2025-01-05) ## Bug Fixes diff --git a/doc/html/driver__st7789_8c_source.html b/doc/html/driver__st7789_8c_source.html index b043270..dadcaeb 100644 --- a/doc/html/driver__st7789_8c_source.html +++ b/doc/html/driver__st7789_8c_source.html @@ -2434,7 +2434,7 @@
3294 
3295  return 4; /* return error */
3296  }
-
3297  handle->delay_ms(100); /* delay 100 ms */
+
3297  handle->delay_ms(25); /* over 10 us */
3298  if (handle->reset_gpio_write(1) != 0) /* write 1 */
3299  {
3300  handle->debug_print("st7789: reset gpio write failed.\n"); /* reset gpio write failed */
@@ -2443,1170 +2443,1171 @@
3303 
3304  return 4; /* return error */
3305  }
-
3306  if (handle->spi_init() != 0) /* spi init */
-
3307  {
-
3308  handle->debug_print("st7789: spi init failed.\n"); /* spi init failed */
-
3309  (void)handle->cmd_data_gpio_deinit(); /* cmd_data_gpio_deinit */
-
3310  (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */
-
3311 
-
3312  return 1; /* return error */
-
3313  }
-
3314  handle->inited = 1; /* flag inited */
-
3315 
-
3316  return 0; /* success return 0 */
-
3317 }
-
3318 
-
3332 uint8_t st7789_deinit(st7789_handle_t *handle)
-
3333 {
-
3334  if (handle == NULL) /* check handle */
-
3335  {
-
3336  return 2; /* return error */
-
3337  }
-
3338  if (handle->inited != 1) /* check handle initialization */
-
3339  {
-
3340  return 3; /* return error */
-
3341  }
-
3342 
-
3343  if (a_st7789_write_byte(handle, ST7789_CMD_SLPIN, ST7789_CMD) != 0) /* write sleep in command */
-
3344  {
-
3345  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
3346 
-
3347  return 1; /* return error */
-
3348  }
-
3349  if (handle->reset_gpio_deinit() != 0) /* reset gpio deinit */
-
3350  {
-
3351  handle->debug_print("st7789: reset gpio deinit failed.\n"); /* reset gpio deinit failed */
-
3352 
-
3353  return 5; /* return error */
-
3354  }
-
3355  if (handle->cmd_data_gpio_deinit() != 0) /* cmd data gpio deinit */
-
3356  {
-
3357  handle->debug_print("st7789: cmd data gpio deinit failed.\n"); /* cmd data gpio deinit failed */
-
3358 
-
3359  return 6; /* return error */
-
3360  }
-
3361  if (handle->spi_deinit() != 0) /* spi deinit */
-
3362  {
-
3363  handle->debug_print("st7789: spi deinit failed.\n"); /* spi deinit failed */
-
3364 
-
3365  return 1; /* return error */
-
3366  }
-
3367  handle->inited = 0; /* flag close */
-
3368 
-
3369  return 0; /* success return 0 */
-
3370 }
-
3371 
-
3383 uint8_t st7789_set_column(st7789_handle_t *handle, uint16_t column)
-
3384 {
-
3385  if (handle == NULL) /* check handle */
-
3386  {
-
3387  return 2; /* return error */
-
3388  }
-
3389  if (handle->inited != 1) /* check handle initialization */
-
3390  {
-
3391  return 3; /* return error */
-
3392  }
-
3393  if (column > 240) /* check column */
-
3394  {
-
3395  handle->debug_print("st7789: column > 240.\n"); /* column > 240 */
-
3396 
-
3397  return 4; /* return error */
-
3398  }
-
3399 
-
3400  handle->column = column; /* set column */
-
3401 
-
3402  return 0; /* success return 0 */
-
3403 }
-
3404 
-
3416 uint8_t st7789_set_row(st7789_handle_t *handle, uint16_t row)
-
3417 {
-
3418  if (handle == NULL) /* check handle */
-
3419  {
-
3420  return 2; /* return error */
-
3421  }
-
3422  if (handle->inited != 1) /* check handle initialization */
-
3423  {
-
3424  return 3; /* return error */
-
3425  }
-
3426  if (row > 320) /* check column */
-
3427  {
-
3428  handle->debug_print("st7789: row > 320.\n"); /* row > 320 */
-
3429 
-
3430  return 4; /* return error */
-
3431  }
-
3432 
-
3433  handle->row = row; /* set row */
-
3434 
-
3435  return 0; /* success return 0 */
-
3436 }
-
3437 
-
3449 uint8_t st7789_clear(st7789_handle_t *handle)
-
3450 {
-
3451  uint8_t buf[4];
-
3452  uint32_t i;
-
3453  uint32_t m;
-
3454  uint32_t n;
-
3455 
-
3456  if (handle == NULL) /* check handle */
-
3457  {
-
3458  return 2; /* return error */
-
3459  }
-
3460  if (handle->inited != 1) /* check handle initialization */
-
3461  {
-
3462  return 3; /* return error */
-
3463  }
-
3464 
-
3465  if (a_st7789_write_byte(handle, ST7789_CMD_CASET, ST7789_CMD) != 0) /* write set column address command */
-
3466  {
-
3467  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
3468 
-
3469  return 1; /* return error */
-
3470  }
-
3471  buf[0] = (0x00 >> 8) & 0xFF; /* start address msb */
-
3472  buf[1] = (0x00 >> 0) & 0xFF; /* start address lsb */
-
3473  buf[2] = ((handle->column - 1) >> 8) & 0xFF; /* end address msb */
-
3474  buf[3] = ((handle->column - 1) >> 0) & 0xFF; /* end address lsb */
-
3475  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
-
3476  {
-
3477  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3478 
-
3479  return 1; /* return error */
-
3480  }
-
3481 
-
3482  if (a_st7789_write_byte(handle, ST7789_CMD_RASET, ST7789_CMD) != 0) /* write set row address command */
-
3483  {
-
3484  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
3485 
-
3486  return 1; /* return error */
-
3487  }
-
3488  buf[0] = (0x00 >> 8) & 0xFF; /* start address msb */
-
3489  buf[1] = (0x00 >> 0) & 0xFF; /* start address lsb */
-
3490  buf[2] = ((handle->row - 1) >> 8) & 0xFF; /* end address msb */
-
3491  buf[3] = ((handle->row - 1) >> 0) & 0xFF; /* end address lsb */
-
3492  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
-
3493  {
-
3494  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3495 
-
3496  return 1; /* return error */
-
3497  }
-
3498 
-
3499  if (a_st7789_write_byte(handle, ST7789_CMD_RAMWR, ST7789_CMD) != 0) /* write memory write command */
-
3500  {
-
3501  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
3502 
-
3503  return 1; /* return error */
-
3504  }
-
3505 
-
3506  if ((handle->format & 0x03) == 0x03) /* rgb444 */
-
3507  {
-
3508  memset(handle->buf, 0x00, sizeof(uint8_t) * ST7789_BUFFER_SIZE); /* clear buffer */
-
3509  m = ((uint32_t)(handle->row) * handle->column * 3 / 2) /
-
3510  ST7789_BUFFER_SIZE; /* total times */
-
3511  n = ((uint32_t)(handle->row) * handle->column * 3 / 2) %
-
3512  ST7789_BUFFER_SIZE; /* the last */
-
3513  for (i = 0; i < m; i++)
-
3514  {
-
3515  if (a_st7789_write_bytes(handle, handle->buf,
-
3516  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
-
3517  {
-
3518  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3519 
-
3520  return 1; /* return error */
-
3521  }
-
3522  }
-
3523  if (n != 0) /* not end */
-
3524  {
-
3525  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
-
3526  {
-
3527  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3528 
-
3529  return 1; /* return error */
-
3530  }
-
3531  }
-
3532  }
-
3533  else if ((handle->format & 0x05) == 0x05) /* rgb565 */
-
3534  {
-
3535  memset(handle->buf, 0x00, sizeof(uint8_t) * ST7789_BUFFER_SIZE); /* clear buffer */
-
3536  m = (uint32_t)(handle->row) * handle->column * 2 / ST7789_BUFFER_SIZE; /* total times */
-
3537  n = (uint32_t)(handle->row) * handle->column * 2 % ST7789_BUFFER_SIZE; /* the last */
-
3538  for (i = 0; i < m; i++)
-
3539  {
-
3540  if (a_st7789_write_bytes(handle, handle->buf,
-
3541  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
-
3542  {
-
3543  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3544 
-
3545  return 1; /* return error */
-
3546  }
-
3547  }
-
3548  if (n != 0) /* not end */
-
3549  {
-
3550  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
-
3551  {
-
3552  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3553 
-
3554  return 1; /* return error */
-
3555  }
-
3556  }
-
3557  }
-
3558  else if ((handle->format & 0x06) == 0x06) /* rgb666 */
-
3559  {
-
3560  memset(handle->buf, 0x00, sizeof(uint8_t) * ST7789_BUFFER_SIZE); /* clear buffer */
-
3561  m = (uint32_t)(handle->row) * handle->column * 3 / ST7789_BUFFER_SIZE; /* total times */
-
3562  n = (uint32_t)(handle->row) * handle->column * 3 % ST7789_BUFFER_SIZE; /* the last */
-
3563  for (i = 0; i < m; i++)
-
3564  {
-
3565  if (a_st7789_write_bytes(handle, handle->buf,
-
3566  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
-
3567  {
-
3568  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3569 
-
3570  return 1; /* return error */
-
3571  }
-
3572  }
-
3573  if (n != 0) /* not end */
-
3574  {
-
3575  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
-
3576  {
-
3577  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3578 
-
3579  return 1; /* return error */
-
3580  }
-
3581  }
-
3582  }
-
3583  else
-
3584  {
-
3585  handle->debug_print("st7789: format is invalid.\n"); /* format is invalid */
-
3586 
-
3587  return 4; /* return error */
-
3588  }
-
3589 
-
3590  return 0; /* success return 0 */
-
3591 }
-
3592 
-
3614 uint8_t st7789_fill_rect(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint32_t color)
-
3615 {
-
3616  uint8_t buf[4];
-
3617  uint32_t i;
-
3618  uint32_t m;
-
3619  uint32_t n;
-
3620 
-
3621  if (handle == NULL) /* check handle */
-
3622  {
-
3623  return 2; /* return error */
-
3624  }
-
3625  if (handle->inited != 1) /* check handle initialization */
-
3626  {
-
3627  return 3; /* return error */
-
3628  }
-
3629  if (left > (handle->column - 1)) /* check left */
-
3630  {
-
3631  handle->debug_print("st7789: left is over column.\n"); /* left is over column */
-
3632 
-
3633  return 4; /* return error */
-
3634  }
-
3635  if (right > (handle->column - 1)) /* check right */
-
3636  {
-
3637  handle->debug_print("st7789: right is over column.\n"); /* right is over column */
-
3638 
-
3639  return 5; /* return error */
-
3640  }
-
3641  if (left >= right) /* check left and right */
-
3642  {
-
3643  handle->debug_print("st7789: left >= right.\n"); /* left >= right */
-
3644 
-
3645  return 6; /* return error */
-
3646  }
-
3647  if (top > (handle->row - 1)) /* check top */
-
3648  {
-
3649  handle->debug_print("st7789: top is over row.\n"); /* top is over row */
-
3650 
-
3651  return 7; /* return error */
-
3652  }
-
3653  if (bottom > (handle->row - 1)) /* check bottom */
-
3654  {
-
3655  handle->debug_print("st7789: bottom is over row.\n"); /* bottom is over row */
-
3656 
-
3657  return 8; /* return error */
-
3658  }
-
3659  if (top >= bottom) /* check top and bottom */
-
3660  {
-
3661  handle->debug_print("st7789: top >= bottom.\n"); /* top >= bottom */
-
3662 
-
3663  return 9; /* return error */
-
3664  }
-
3665 
-
3666  if (a_st7789_write_byte(handle, ST7789_CMD_CASET, ST7789_CMD) != 0) /* write set column address command */
-
3667  {
-
3668  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
3669 
-
3670  return 1; /* return error */
-
3671  }
-
3672  buf[0] = (left >> 8) & 0xFF; /* start address msb */
-
3673  buf[1] = (left >> 0) & 0xFF; /* start address lsb */
-
3674  buf[2] = ((right) >> 8) & 0xFF; /* end address msb */
-
3675  buf[3] = ((right) >> 0) & 0xFF; /* end address lsb */
-
3676  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
-
3677  {
-
3678  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3679 
-
3680  return 1; /* return error */
-
3681  }
-
3682 
-
3683  if (a_st7789_write_byte(handle, ST7789_CMD_RASET, ST7789_CMD) != 0) /* write set row address command */
-
3684  {
-
3685  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
3686 
-
3687  return 1; /* return error */
-
3688  }
-
3689  buf[0] = (top >> 8) & 0xFF; /* start address msb */
-
3690  buf[1] = (top >> 0) & 0xFF; /* start address lsb */
-
3691  buf[2] = ((bottom) >> 8) & 0xFF; /* end address msb */
-
3692  buf[3] = ((bottom) >> 0) & 0xFF; /* end address lsb */
-
3693  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
-
3694  {
-
3695  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3696 
-
3697  return 1; /* return error */
-
3698  }
-
3699 
-
3700  if (a_st7789_write_byte(handle, ST7789_CMD_RAMWR, ST7789_CMD) != 0) /* write memory write command */
-
3701  {
-
3702  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
3703 
-
3704  return 1; /* return error */
-
3705  }
-
3706 
-
3707  if ((handle->format & 0x03) == 0x03) /* rgb444 */
-
3708  {
-
3709  for (i = 0; i < ST7789_BUFFER_SIZE; i += 3) /* fill the buffer */
-
3710  {
-
3711  handle->buf[i] = (((color >> 8) & 0xF) << 4) |
-
3712  (((color >> 4) & 0xF) << 0); /* set the color */
-
3713  handle->buf[i + 1] = (((color >> 0) & 0xF) << 4) |
-
3714  (((color >> 8) & 0xF) << 0); /* set the color */
-
3715  handle->buf[i + 2] = (((color >> 4) & 0xF) << 4) |
-
3716  (((color >> 0) & 0xF) << 0); /* set the color */
-
3717  }
-
3718  m = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 3 / 2) /
-
3719  ST7789_BUFFER_SIZE; /* total times */
-
3720  n = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 3 / 2) %
-
3721  ST7789_BUFFER_SIZE; /* the last */
-
3722  for (i = 0; i < m; i++)
-
3723  {
-
3724  if (a_st7789_write_bytes(handle, handle->buf,
-
3725  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
-
3726  {
-
3727  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3728 
-
3729  return 1; /* return error */
-
3730  }
-
3731  }
-
3732  if (n != 0) /* not end */
-
3733  {
-
3734  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
-
3735  {
-
3736  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3737 
-
3738  return 1; /* return error */
-
3739  }
-
3740  }
-
3741  }
-
3742  else if ((handle->format & 0x05) == 0x05) /* rgb565 */
-
3743  {
-
3744  for (i = 0; i < ST7789_BUFFER_SIZE; i += 2) /* fill the buffer */
-
3745  {
-
3746  handle->buf[i] = (color >> 8) & 0xFF; /* set the color */
-
3747  handle->buf[i + 1] = (color >> 0) & 0xFF; /* set the color */
-
3748  }
-
3749  m = (uint32_t)(right - left + 1) * (bottom - top + 1) * 2 /
-
3750  ST7789_BUFFER_SIZE; /* total times */
-
3751  n = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 2) %
-
3752  ST7789_BUFFER_SIZE; /* the last */
-
3753  for (i = 0; i < m; i++)
-
3754  {
-
3755  if (a_st7789_write_bytes(handle, handle->buf,
-
3756  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
-
3757  {
-
3758  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3759 
-
3760  return 1; /* return error */
-
3761  }
-
3762  }
-
3763  if (n != 0) /* not end */
-
3764  {
-
3765  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
-
3766  {
-
3767  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3768 
-
3769  return 1; /* return error */
-
3770  }
-
3771  }
-
3772  }
-
3773  else if ((handle->format & 0x06) == 0x06) /* rgb666 */
-
3774  {
-
3775  for (i = 0; i < ST7789_BUFFER_SIZE; i += 3) /* fill the buffer */
-
3776  {
-
3777  handle->buf[i] = ((color >> 12) & 0x3F) << 2; /* set the color */
-
3778  handle->buf[i + 1] = ((color >> 6) & 0x3F) << 2; /* set the color */
-
3779  handle->buf[i + 2] = ((color >> 0) & 0x3F) << 2; /* set the color */
-
3780  }
-
3781  m = (uint32_t)(right - left + 1) * (bottom - top + 1) * 3 /
-
3782  ST7789_BUFFER_SIZE; /* total times */
-
3783  n = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 3) %
-
3784  ST7789_BUFFER_SIZE; /* the last */
-
3785  for (i = 0; i < m; i++)
-
3786  {
-
3787  if (a_st7789_write_bytes(handle, handle->buf,
-
3788  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
-
3789  {
-
3790  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3791 
-
3792  return 1; /* return error */
-
3793  }
-
3794  }
-
3795  if (n != 0) /* not end */
-
3796  {
-
3797  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
-
3798  {
-
3799  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3800 
-
3801  return 1; /* return error */
-
3802  }
-
3803  }
-
3804  }
-
3805  else
-
3806  {
-
3807  handle->debug_print("st7789: format is invalid.\n"); /* format is invalid */
-
3808 
-
3809  return 4; /* return error */
-
3810  }
-
3811 
-
3812  return 0; /* success return 0 */
-
3813 }
-
3814 
-
3836 uint8_t st7789_draw_picture_12bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint16_t *image)
-
3837 {
-
3838  uint8_t buf[4];
-
3839  uint32_t i;
-
3840  uint32_t j;
-
3841  uint32_t m;
-
3842  uint32_t n;
-
3843  uint32_t point;
-
3844 
-
3845  if (handle == NULL) /* check handle */
-
3846  {
-
3847  return 2; /* return error */
-
3848  }
-
3849  if (handle->inited != 1) /* check handle initialization */
-
3850  {
-
3851  return 3; /* return error */
-
3852  }
-
3853  if (left > (handle->column - 1)) /* check left */
-
3854  {
-
3855  handle->debug_print("st7789: left is over column.\n"); /* left is over column */
-
3856 
-
3857  return 4; /* return error */
-
3858  }
-
3859  if (right > (handle->column - 1)) /* check right */
-
3860  {
-
3861  handle->debug_print("st7789: right is over column.\n"); /* right is over column */
-
3862 
-
3863  return 5; /* return error */
-
3864  }
-
3865  if (left >= right) /* check left and right */
-
3866  {
-
3867  handle->debug_print("st7789: left >= right.\n"); /* left >= right */
-
3868 
-
3869  return 6; /* return error */
-
3870  }
-
3871  if (top > (handle->row - 1)) /* check top */
-
3872  {
-
3873  handle->debug_print("st7789: top is over row.\n"); /* top is over row */
-
3874 
-
3875  return 7; /* return error */
-
3876  }
-
3877  if (bottom > (handle->row - 1)) /* check bottom */
-
3878  {
-
3879  handle->debug_print("st7789: bottom is over row.\n"); /* bottom is over row */
-
3880 
-
3881  return 8; /* return error */
-
3882  }
-
3883  if (top >= bottom) /* check top and bottom */
-
3884  {
-
3885  handle->debug_print("st7789: top >= bottom.\n"); /* top >= bottom */
-
3886 
-
3887  return 9; /* return error */
-
3888  }
-
3889 
-
3890  if (a_st7789_write_byte(handle, ST7789_CMD_CASET, ST7789_CMD) != 0) /* write set column address command */
-
3891  {
-
3892  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
3893 
-
3894  return 1; /* return error */
-
3895  }
-
3896  buf[0] = (left >> 8) & 0xFF; /* start address msb */
-
3897  buf[1] = (left >> 0) & 0xFF; /* start address lsb */
-
3898  buf[2] = ((right) >> 8) & 0xFF; /* end address msb */
-
3899  buf[3] = ((right) >> 0) & 0xFF; /* end address lsb */
-
3900  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
-
3901  {
-
3902  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3903 
-
3904  return 1; /* return error */
-
3905  }
-
3906 
-
3907  if (a_st7789_write_byte(handle, ST7789_CMD_RASET, ST7789_CMD) != 0) /* write set row address command */
-
3908  {
-
3909  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
3910 
-
3911  return 1; /* return error */
-
3912  }
-
3913  buf[0] = (top >> 8) & 0xFF; /* start address msb */
-
3914  buf[1] = (top >> 0) & 0xFF; /* start address lsb */
-
3915  buf[2] = ((bottom) >> 8) & 0xFF; /* end address msb */
-
3916  buf[3] = ((bottom) >> 0) & 0xFF; /* end address lsb */
-
3917  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
-
3918  {
-
3919  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3920 
-
3921  return 1; /* return error */
-
3922  }
-
3923 
-
3924  if (a_st7789_write_byte(handle, ST7789_CMD_RAMWR, ST7789_CMD) != 0) /* write memory write command */
-
3925  {
-
3926  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
3927 
-
3928  return 1; /* return error */
-
3929  }
-
3930 
-
3931  if ((handle->format & 0x03) == 0x03) /* rgb444 */
-
3932  {
-
3933  uint16_t r;
-
3934  uint16_t c;
-
3935  uint16_t color;
-
3936 
-
3937  c = right - left + 1; /* column */
-
3938  r = bottom - top + 1; /* row */
-
3939  point = 0; /* image point init 0 */
-
3940  m = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 3 / 2) /
-
3941  ST7789_BUFFER_SIZE; /* total times */
-
3942  n = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 3 / 2) %
-
3943  ST7789_BUFFER_SIZE; /* the last */
-
3944  for (i = 0; i < m; i++)
-
3945  {
-
3946  for (j = 0; j < ST7789_BUFFER_SIZE; j += 3) /* fill the buffer */
-
3947  {
-
3948  color = image[(point % c) * r + (point / c)]; /* set color */
-
3949  handle->buf[i] = (((color >> 8) & 0xF) << 4) |
-
3950  (((color >> 4) & 0xF) << 0); /* set the color */
-
3951  handle->buf[i + 1] = (((color >> 0) & 0xF) << 4) |
-
3952  (((color >> 8) & 0xF) << 0); /* set the color */
-
3953  handle->buf[i + 2] = (((color >> 4) & 0xF) << 4) |
-
3954  (((color >> 0) & 0xF) << 0); /* set the color */
-
3955  point++; /* point++ */
-
3956  }
-
3957  if (a_st7789_write_bytes(handle, handle->buf,
-
3958  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
-
3959  {
-
3960  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3961 
-
3962  return 1; /* return error */
-
3963  }
-
3964  }
-
3965  if (n != 0) /* not end */
-
3966  {
-
3967  for (j = 0; j < n; j += 3) /* fill the buffer */
-
3968  {
-
3969  color = image[(point % c) * r + (point / c)]; /* set color */
-
3970  handle->buf[i] = (((color >> 8) & 0xF) << 4) |
-
3971  (((color >> 4) & 0xF) << 0); /* set the color */
-
3972  handle->buf[i + 1] = (((color >> 0) & 0xF) << 4) |
-
3973  (((color >> 8) & 0xF) << 0); /* set the color */
-
3974  handle->buf[i + 2] = (((color >> 4) & 0xF) << 4) |
-
3975  (((color >> 0) & 0xF) << 0); /* set the color */
-
3976  point++; /* point++ */
-
3977  }
-
3978  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
-
3979  {
-
3980  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
3981 
-
3982  return 1; /* return error */
-
3983  }
-
3984  }
-
3985  }
-
3986  else
-
3987  {
-
3988  handle->debug_print("st7789: format is invalid.\n"); /* format is invalid */
-
3989 
-
3990  return 4; /* return error */
-
3991  }
-
3992 
-
3993  return 0; /* success return 0 */
-
3994 }
-
3995 
-
4017 uint8_t st7789_draw_picture_16bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint16_t *image)
-
4018 {
-
4019  uint8_t buf[4];
-
4020  uint32_t i;
-
4021  uint32_t j;
-
4022  uint32_t m;
-
4023  uint32_t n;
-
4024  uint32_t point;
-
4025 
-
4026  if (handle == NULL) /* check handle */
-
4027  {
-
4028  return 2; /* return error */
-
4029  }
-
4030  if (handle->inited != 1) /* check handle initialization */
-
4031  {
-
4032  return 3; /* return error */
-
4033  }
-
4034  if (left > (handle->column - 1)) /* check left */
-
4035  {
-
4036  handle->debug_print("st7789: left is over column.\n"); /* left is over column */
-
4037 
-
4038  return 4; /* return error */
-
4039  }
-
4040  if (right > (handle->column - 1)) /* check right */
-
4041  {
-
4042  handle->debug_print("st7789: right is over column.\n"); /* right is over column */
-
4043 
-
4044  return 5; /* return error */
-
4045  }
-
4046  if (left >= right) /* check left and right */
-
4047  {
-
4048  handle->debug_print("st7789: left >= right.\n"); /* left >= right */
-
4049 
-
4050  return 6; /* return error */
-
4051  }
-
4052  if (top > (handle->row - 1)) /* check top */
-
4053  {
-
4054  handle->debug_print("st7789: top is over row.\n"); /* top is over row */
-
4055 
-
4056  return 7; /* return error */
-
4057  }
-
4058  if (bottom > (handle->row - 1)) /* check bottom */
-
4059  {
-
4060  handle->debug_print("st7789: bottom is over row.\n"); /* bottom is over row */
-
4061 
-
4062  return 8; /* return error */
-
4063  }
-
4064  if (top >= bottom) /* check top and bottom */
-
4065  {
-
4066  handle->debug_print("st7789: top >= bottom.\n"); /* top >= bottom */
-
4067 
-
4068  return 9; /* return error */
-
4069  }
-
4070 
-
4071  if (a_st7789_write_byte(handle, ST7789_CMD_CASET, ST7789_CMD) != 0) /* write set column address command */
-
4072  {
-
4073  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
4074 
-
4075  return 1; /* return error */
-
4076  }
-
4077  buf[0] = (left >> 8) & 0xFF; /* start address msb */
-
4078  buf[1] = (left >> 0) & 0xFF; /* start address lsb */
-
4079  buf[2] = ((right) >> 8) & 0xFF; /* end address msb */
-
4080  buf[3] = ((right) >> 0) & 0xFF; /* end address lsb */
-
4081  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
-
4082  {
-
4083  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
4084 
-
4085  return 1; /* return error */
-
4086  }
-
4087 
-
4088  if (a_st7789_write_byte(handle, ST7789_CMD_RASET, ST7789_CMD) != 0) /* write set row address command */
-
4089  {
-
4090  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
4091 
-
4092  return 1; /* return error */
-
4093  }
-
4094  buf[0] = (top >> 8) & 0xFF; /* start address msb */
-
4095  buf[1] = (top >> 0) & 0xFF; /* start address lsb */
-
4096  buf[2] = ((bottom) >> 8) & 0xFF; /* end address msb */
-
4097  buf[3] = ((bottom) >> 0) & 0xFF; /* end address lsb */
-
4098  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
-
4099  {
-
4100  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
4101 
-
4102  return 1; /* return error */
-
4103  }
-
4104 
-
4105  if (a_st7789_write_byte(handle, ST7789_CMD_RAMWR, ST7789_CMD) != 0) /* write memory write command */
-
4106  {
-
4107  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
4108 
-
4109  return 1; /* return error */
-
4110  }
-
4111 
-
4112  if ((handle->format & 0x05) == 0x05) /* rgb565 */
-
4113  {
-
4114  uint16_t r;
-
4115  uint16_t c;
-
4116  uint16_t color;
-
4117 
-
4118  c = right - left + 1; /* column */
-
4119  r = bottom - top + 1; /* row */
-
4120  point = 0; /* image point init 0 */
-
4121  m = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 2) /
-
4122  ST7789_BUFFER_SIZE; /* total times */
-
4123  n = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 2) %
-
4124  ST7789_BUFFER_SIZE; /* the last */
-
4125  for (i = 0; i < m; i++)
-
4126  {
-
4127  for (j = 0; j < ST7789_BUFFER_SIZE; j += 2) /* fill the buffer */
-
4128  {
-
4129  color = image[(point % c) * r + (point / c)]; /* set color */
-
4130  handle->buf[j] = (color >> 8) & 0xFF; /* set the color */
-
4131  handle->buf[j + 1] = (color >> 0) & 0xFF; /* set the color */
-
4132  point++; /* point++ */
-
4133  }
-
4134  if (a_st7789_write_bytes(handle, handle->buf,
-
4135  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
-
4136  {
-
4137  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
4138 
-
4139  return 1; /* return error */
-
4140  }
-
4141  }
-
4142  if (n != 0) /* not end */
-
4143  {
-
4144  for (j = 0; j < n; j += 2) /* fill the buffer */
-
4145  {
-
4146  color = image[(point % c) * r + (point / c)]; /* set color */
-
4147  handle->buf[j] = (color >> 8) & 0xFF; /* set the color */
-
4148  handle->buf[j + 1] = (color >> 0) & 0xFF; /* set the color */
-
4149  point++; /* point++ */
-
4150  }
-
4151  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
-
4152  {
-
4153  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
4154 
-
4155  return 1; /* return error */
-
4156  }
-
4157  }
-
4158  }
-
4159  else
-
4160  {
-
4161  handle->debug_print("st7789: format is invalid.\n"); /* format is invalid */
-
4162 
-
4163  return 4; /* return error */
-
4164  }
-
4165 
-
4166  return 0; /* success return 0 */
-
4167 }
-
4168 
-
4190 uint8_t st7789_draw_picture_18bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint32_t *image)
-
4191 {
-
4192  uint8_t buf[4];
-
4193  uint32_t i;
-
4194  uint32_t j;
-
4195  uint32_t m;
-
4196  uint32_t n;
-
4197  uint32_t point;
-
4198 
-
4199  if (handle == NULL) /* check handle */
-
4200  {
-
4201  return 2; /* return error */
-
4202  }
-
4203  if (handle->inited != 1) /* check handle initialization */
-
4204  {
-
4205  return 3; /* return error */
-
4206  }
-
4207  if (left > (handle->column - 1)) /* check left */
-
4208  {
-
4209  handle->debug_print("st7789: left is over column.\n"); /* left is over column */
-
4210 
-
4211  return 4; /* return error */
-
4212  }
-
4213  if (right > (handle->column - 1)) /* check right */
-
4214  {
-
4215  handle->debug_print("st7789: right is over column.\n"); /* right is over column */
-
4216 
-
4217  return 5; /* return error */
-
4218  }
-
4219  if (left >= right) /* check left and right */
-
4220  {
-
4221  handle->debug_print("st7789: left >= right.\n"); /* left >= right */
-
4222 
-
4223  return 6; /* return error */
-
4224  }
-
4225  if (top > (handle->row - 1)) /* check top */
-
4226  {
-
4227  handle->debug_print("st7789: top is over row.\n"); /* top is over row */
-
4228 
-
4229  return 7; /* return error */
-
4230  }
-
4231  if (bottom > (handle->row - 1)) /* check bottom */
-
4232  {
-
4233  handle->debug_print("st7789: bottom is over row.\n"); /* bottom is over row */
-
4234 
-
4235  return 8; /* return error */
-
4236  }
-
4237  if (top >= bottom) /* check top and bottom */
-
4238  {
-
4239  handle->debug_print("st7789: top >= bottom.\n"); /* top >= bottom */
-
4240 
-
4241  return 9; /* return error */
-
4242  }
-
4243 
-
4244  if (a_st7789_write_byte(handle, ST7789_CMD_CASET, ST7789_CMD) != 0) /* write set column address command */
-
4245  {
-
4246  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
4247 
-
4248  return 1; /* return error */
-
4249  }
-
4250  buf[0] = (left >> 8) & 0xFF; /* start address msb */
-
4251  buf[1] = (left >> 0) & 0xFF; /* start address lsb */
-
4252  buf[2] = ((right) >> 8) & 0xFF; /* end address msb */
-
4253  buf[3] = ((right) >> 0) & 0xFF; /* end address lsb */
-
4254  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
-
4255  {
-
4256  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
4257 
-
4258  return 1; /* return error */
-
4259  }
-
4260 
-
4261  if (a_st7789_write_byte(handle, ST7789_CMD_RASET, ST7789_CMD) != 0) /* write set row address command */
-
4262  {
-
4263  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
4264 
-
4265  return 1; /* return error */
-
4266  }
-
4267  buf[0] = (top >> 8) & 0xFF; /* start address msb */
-
4268  buf[1] = (top >> 0) & 0xFF; /* start address lsb */
-
4269  buf[2] = ((bottom) >> 8) & 0xFF; /* end address msb */
-
4270  buf[3] = ((bottom) >> 0) & 0xFF; /* end address lsb */
-
4271  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
-
4272  {
-
4273  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
4274 
-
4275  return 1; /* return error */
-
4276  }
-
4277 
-
4278  if (a_st7789_write_byte(handle, ST7789_CMD_RAMWR, ST7789_CMD) != 0) /* write memory write command */
-
4279  {
-
4280  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
4281 
-
4282  return 1; /* return error */
-
4283  }
-
4284 
-
4285  if ((handle->format & 0x06) == 0x06) /* rgb666 */
-
4286  {
-
4287  uint16_t r;
-
4288  uint16_t c;
-
4289  uint32_t color;
-
4290 
-
4291  c = right - left + 1; /* column */
-
4292  r = bottom - top + 1; /* row */
-
4293  point = 0; /* image point init 0 */
-
4294  m = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 3) /
-
4295  ST7789_BUFFER_SIZE; /* total times */
-
4296  n = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 3) %
-
4297  ST7789_BUFFER_SIZE; /* the last */
-
4298  for (i = 0; i < m; i++)
-
4299  {
-
4300  for (j = 0; j < ST7789_BUFFER_SIZE; j += 3) /* fill the buffer */
-
4301  {
-
4302  color = image[(point % c) * r + (point / c)]; /* set color */
-
4303  handle->buf[j] = ((color >> 12) & 0x3F) << 2; /* set the color */
-
4304  handle->buf[j + 1] = ((color >> 6) & 0x3F) << 2; /* set the color */
-
4305  handle->buf[j + 2] = ((color >> 0) & 0x3F) << 2; /* set the color */
-
4306  point++; /* point++ */
-
4307  }
-
4308  if (a_st7789_write_bytes(handle, handle->buf,
-
4309  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
-
4310  {
-
4311  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
4312 
-
4313  return 1; /* return error */
-
4314  }
-
4315  }
-
4316  if (n != 0) /* not end */
-
4317  {
-
4318  for (j = 0; j < n; j += 3) /* fill the buffer */
-
4319  {
-
4320  color = image[(point % c) * r + (point / c)]; /* set color */
-
4321  handle->buf[j] = ((color >> 12) & 0x3F) << 2; /* set the color */
-
4322  handle->buf[j + 1] = ((color >> 6) & 0x3F) << 2; /* set the color */
-
4323  handle->buf[j + 2] = ((color >> 0) & 0x3F) << 2; /* set the color */
-
4324  point++; /* point++ */
-
4325  }
-
4326  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
-
4327  {
-
4328  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
4329 
-
4330  return 1; /* return error */
-
4331  }
-
4332  }
-
4333  }
-
4334  else
-
4335  {
-
4336  handle->debug_print("st7789: format is invalid.\n"); /* format is invalid */
-
4337 
-
4338  return 4; /* return error */
-
4339  }
-
4340 
-
4341  return 0; /* success return 0 */
-
4342 }
-
4343 
-
4355 static uint8_t a_st7789_draw_point(st7789_handle_t *handle, uint16_t x, uint16_t y, uint32_t color)
-
4356 {
-
4357  uint8_t buf[4];
-
4358 
-
4359  if (a_st7789_write_byte(handle, ST7789_CMD_CASET, ST7789_CMD) != 0) /* write set column address command */
-
4360  {
-
4361  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
4362 
-
4363  return 1; /* return error */
-
4364  }
-
4365  buf[0] = (x >> 8) & 0xFF; /* start address msb */
-
4366  buf[1] = (x >> 0) & 0xFF; /* start address lsb */
-
4367  buf[2] = (x >> 8) & 0xFF; /* end address msb */
-
4368  buf[3] = (x >> 0) & 0xFF; /* end address lsb */
-
4369  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
-
4370  {
-
4371  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
4372 
-
4373  return 1; /* return error */
-
4374  }
-
4375 
-
4376  if (a_st7789_write_byte(handle, ST7789_CMD_RASET, ST7789_CMD) != 0) /* write set row address command */
-
4377  {
-
4378  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
4379 
-
4380  return 1; /* return error */
-
4381  }
-
4382  buf[0] = (y >> 8) & 0xFF; /* start address msb */
-
4383  buf[1] = (y >> 0) & 0xFF; /* start address lsb */
-
4384  buf[2] = (y >> 8) & 0xFF; /* end address msb */
-
4385  buf[3] = (y >> 0) & 0xFF; /* end address lsb */
-
4386  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
-
4387  {
-
4388  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
4389 
-
4390  return 1; /* return error */
-
4391  }
-
4392 
-
4393  if (a_st7789_write_byte(handle, ST7789_CMD_RAMWR, ST7789_CMD) != 0) /* write memory write command */
-
4394  {
-
4395  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
-
4396 
-
4397  return 1; /* return error */
-
4398  }
-
4399 
-
4400  if ((handle->format & 0x03) == 0x03) /* rgb444 */
-
4401  {
-
4402  handle->buf[0] = (((color >> 8) & 0xF) << 4) |
-
4403  (((color >> 4) & 0xF) << 0); /* set the color */
-
4404  handle->buf[1] = (((color >> 0) & 0xF) << 4); /* set the color */
-
4405  if (a_st7789_write_bytes(handle, handle->buf,
-
4406  2, ST7789_DATA) != 0) /* write data */
-
4407  {
-
4408  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
4409 
-
4410  return 1; /* return error */
-
4411  }
-
4412  }
-
4413  else if ((handle->format & 0x05) == 0x05) /* rgb565 */
-
4414  {
-
4415  handle->buf[0] = (color >> 8) & 0xFF; /* set the color */
-
4416  handle->buf[1] = (color >> 0) & 0xFF; /* set the color */
-
4417  if (a_st7789_write_bytes(handle, handle->buf,
-
4418  2, ST7789_DATA) != 0) /* write data */
-
4419  {
-
4420  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
4421 
-
4422  return 1; /* return error */
-
4423  }
-
4424  }
-
4425  else if ((handle->format & 0x06) == 0x06) /* rgb666 */
-
4426  {
-
4427  handle->buf[0] = ((color >> 12) & 0x3F) << 2; /* set the color */
-
4428  handle->buf[1] = ((color >> 6) & 0x3F) << 2; /* set the color */
-
4429  handle->buf[2] = ((color >> 0) & 0x3F) << 2; /* set the color */
-
4430  if (a_st7789_write_bytes(handle, handle->buf,
-
4431  3, ST7789_DATA) != 0) /* write data */
-
4432  {
-
4433  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
-
4434 
-
4435  return 1; /* return error */
-
4436  }
-
4437  }
-
4438  else
-
4439  {
-
4440  handle->debug_print("st7789: format is invalid.\n"); /* format is invalid */
-
4441 
-
4442  return 4; /* return error */
-
4443  }
-
4444 
-
4445  return 0; /* success return 0 */
-
4446 }
-
4447 
-
4461 static uint8_t a_st7789_show_char(st7789_handle_t *handle, uint16_t x, uint16_t y, uint8_t chr, uint8_t size, uint32_t color)
-
4462 {
-
4463  uint8_t temp, t, t1;
-
4464  uint16_t y0 = y;
-
4465  uint8_t csize = (size / 8 + ((size % 8) ? 1 : 0)) * (size / 2); /* get size */
-
4466 
-
4467  chr = chr - ' '; /* get index */
-
4468  for (t = 0; t < csize; t++) /* write size */
-
4469  {
-
4470  if (size == 12) /* if size 12 */
-
4471  {
-
4472  temp = gsc_st7789_ascii_1206[chr][t]; /* get ascii 1206 */
-
4473  }
-
4474  else if (size == 16) /* if size 16 */
-
4475  {
-
4476  temp = gsc_st7789_ascii_1608[chr][t]; /* get ascii 1608 */
-
4477  }
-
4478  else if(size == 24) /* if size 24 */
-
4479  {
-
4480  temp = gsc_st7789_ascii_2412[chr][t]; /* get ascii 2412 */
-
4481  }
-
4482  else
-
4483  {
-
4484  return 1; /* return error */
-
4485  }
-
4486  for (t1 = 0; t1 < 8; t1++) /* write one line */
-
4487  {
-
4488  if ((temp & 0x80) != 0) /* if 1 */
-
4489  {
-
4490  if (a_st7789_draw_point(handle, x, y, color) != 0) /* draw point */
-
4491  {
-
4492  return 1; /* return error */
-
4493  }
-
4494  }
-
4495  temp <<= 1; /* left shift 1 */
-
4496  y++;
-
4497  if ((y - y0) == size) /* reset size */
-
4498  {
-
4499  y = y0; /* set y */
-
4500  x++; /* x++ */
-
4501 
-
4502  break; /* break */
-
4503  }
-
4504  }
-
4505  }
-
4506 
-
4507  return 0; /* success return 0 */
-
4508 }
-
4509 
-
4527 uint8_t st7789_write_string(st7789_handle_t *handle, uint16_t x, uint16_t y, char *str, uint16_t len, uint32_t color, st7789_font_t font)
-
4528 {
-
4529  if (handle == NULL) /* check handle */
-
4530  {
-
4531  return 2; /* return error */
-
4532  }
-
4533  if (handle->inited != 1) /* check handle initialization */
-
4534  {
-
4535  return 3; /* return error */
-
4536  }
-
4537  if((x >= handle->column) || (y >= handle->row)) /* check x, y */
-
4538  {
-
4539  handle->debug_print("ssd1351: x or y is invalid.\n"); /* x or y is invalid */
-
4540 
-
4541  return 4; /* return error */
-
4542  }
-
4543 
-
4544  while ((len != 0) && (*str <= '~') && (*str >= ' ')) /* write all string */
-
4545  {
-
4546  if (x >= (handle->column - (font / 2))) /* check x point */
-
4547  {
-
4548  x = 0; /* set x */
-
4549  y += (uint8_t)font; /* set next row */
-
4550  }
-
4551  if (y >= (handle->row - font)) /* check y pont */
-
4552  {
-
4553  y = x = 0; /* reset to 0 */
-
4554  }
-
4555  if (a_st7789_show_char(handle, x, y, *str, font, color) != 0) /* show a char */
-
4556  {
-
4557  return 1; /* return error */
-
4558  }
-
4559  x += (uint8_t)(font / 2); /* x + font/2 */
-
4560  str++; /* str address++ */
-
4561  len--; /* str length-- */
-
4562  }
-
4563 
-
4564  return 0; /* success return 0 */
-
4565 }
-
4566 
-
4582 uint8_t st7789_draw_point(st7789_handle_t *handle, uint16_t x, uint16_t y, uint32_t color)
-
4583 {
-
4584  if (handle == NULL) /* check handle */
-
4585  {
-
4586  return 2; /* return error */
-
4587  }
-
4588  if (handle->inited != 1) /* check handle initialization */
-
4589  {
-
4590  return 3; /* return error */
-
4591  }
-
4592  if (x >= handle->column) /* check x */
-
4593  {
-
4594  handle->debug_print("ssd1351: x is over column.\n"); /* x is over column */
-
4595 
-
4596  return 4; /* return error */
-
4597  }
-
4598  if (y >= handle->row) /* check y */
-
4599  {
-
4600  handle->debug_print("ssd1351: y is over row.\n"); /* y is over row */
-
4601 
-
4602  return 5; /* return error */
-
4603  }
-
4604 
-
4605  return a_st7789_draw_point(handle, x, y, color); /* draw point */
-
4606 }
-
4607 
-
4619 uint8_t st7789_write_cmd(st7789_handle_t *handle, uint8_t cmd)
-
4620 {
-
4621  if (handle == NULL) /* check handle */
-
4622  {
-
4623  return 2; /* return error */
-
4624  }
-
4625  if (handle->inited != 1) /* check handle initialization */
-
4626  {
-
4627  return 3; /* return error */
-
4628  }
-
4629 
-
4630  return a_st7789_write_byte(handle, cmd, ST7789_CMD); /* write command */
-
4631 }
-
4632 
-
4644 uint8_t st7789_write_data(st7789_handle_t *handle, uint8_t data)
-
4645 {
-
4646  if (handle == NULL) /* check handle */
-
4647  {
-
4648  return 2; /* return error */
-
4649  }
-
4650  if (handle->inited != 1) /* check handle initialization */
-
4651  {
-
4652  return 3; /* return error */
-
4653  }
-
4654 
-
4655  return a_st7789_write_byte(handle, data, ST7789_DATA); /* write data */
-
4656 }
-
4657 
-
4666 uint8_t st7789_info(st7789_info_t *info)
-
4667 {
-
4668  if (info == NULL) /* check handle */
-
4669  {
-
4670  return 2; /* return error */
-
4671  }
-
4672 
-
4673  memset(info, 0, sizeof(st7789_info_t)); /* initialize st7789 info structure */
-
4674  strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
-
4675  strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
-
4676  strncpy(info->interface, "SPI", 8); /* copy interface name */
-
4677  info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
-
4678  info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
-
4679  info->max_current_ma = MAX_CURRENT; /* set maximum current */
-
4680  info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
-
4681  info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
-
4682  info->driver_version = DRIVER_VERSION; /* set driver version */
-
4683 
-
4684  return 0; /* success return 0 */
-
4685 }
+
3306  handle->delay_ms(125); /* over 120 ms */
+
3307  if (handle->spi_init() != 0) /* spi init */
+
3308  {
+
3309  handle->debug_print("st7789: spi init failed.\n"); /* spi init failed */
+
3310  (void)handle->cmd_data_gpio_deinit(); /* cmd_data_gpio_deinit */
+
3311  (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */
+
3312 
+
3313  return 1; /* return error */
+
3314  }
+
3315  handle->inited = 1; /* flag inited */
+
3316 
+
3317  return 0; /* success return 0 */
+
3318 }
+
3319 
+
3333 uint8_t st7789_deinit(st7789_handle_t *handle)
+
3334 {
+
3335  if (handle == NULL) /* check handle */
+
3336  {
+
3337  return 2; /* return error */
+
3338  }
+
3339  if (handle->inited != 1) /* check handle initialization */
+
3340  {
+
3341  return 3; /* return error */
+
3342  }
+
3343 
+
3344  if (a_st7789_write_byte(handle, ST7789_CMD_SLPIN, ST7789_CMD) != 0) /* write sleep in command */
+
3345  {
+
3346  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
3347 
+
3348  return 1; /* return error */
+
3349  }
+
3350  if (handle->reset_gpio_deinit() != 0) /* reset gpio deinit */
+
3351  {
+
3352  handle->debug_print("st7789: reset gpio deinit failed.\n"); /* reset gpio deinit failed */
+
3353 
+
3354  return 5; /* return error */
+
3355  }
+
3356  if (handle->cmd_data_gpio_deinit() != 0) /* cmd data gpio deinit */
+
3357  {
+
3358  handle->debug_print("st7789: cmd data gpio deinit failed.\n"); /* cmd data gpio deinit failed */
+
3359 
+
3360  return 6; /* return error */
+
3361  }
+
3362  if (handle->spi_deinit() != 0) /* spi deinit */
+
3363  {
+
3364  handle->debug_print("st7789: spi deinit failed.\n"); /* spi deinit failed */
+
3365 
+
3366  return 1; /* return error */
+
3367  }
+
3368  handle->inited = 0; /* flag close */
+
3369 
+
3370  return 0; /* success return 0 */
+
3371 }
+
3372 
+
3384 uint8_t st7789_set_column(st7789_handle_t *handle, uint16_t column)
+
3385 {
+
3386  if (handle == NULL) /* check handle */
+
3387  {
+
3388  return 2; /* return error */
+
3389  }
+
3390  if (handle->inited != 1) /* check handle initialization */
+
3391  {
+
3392  return 3; /* return error */
+
3393  }
+
3394  if (column > 240) /* check column */
+
3395  {
+
3396  handle->debug_print("st7789: column > 240.\n"); /* column > 240 */
+
3397 
+
3398  return 4; /* return error */
+
3399  }
+
3400 
+
3401  handle->column = column; /* set column */
+
3402 
+
3403  return 0; /* success return 0 */
+
3404 }
+
3405 
+
3417 uint8_t st7789_set_row(st7789_handle_t *handle, uint16_t row)
+
3418 {
+
3419  if (handle == NULL) /* check handle */
+
3420  {
+
3421  return 2; /* return error */
+
3422  }
+
3423  if (handle->inited != 1) /* check handle initialization */
+
3424  {
+
3425  return 3; /* return error */
+
3426  }
+
3427  if (row > 320) /* check column */
+
3428  {
+
3429  handle->debug_print("st7789: row > 320.\n"); /* row > 320 */
+
3430 
+
3431  return 4; /* return error */
+
3432  }
+
3433 
+
3434  handle->row = row; /* set row */
+
3435 
+
3436  return 0; /* success return 0 */
+
3437 }
+
3438 
+
3450 uint8_t st7789_clear(st7789_handle_t *handle)
+
3451 {
+
3452  uint8_t buf[4];
+
3453  uint32_t i;
+
3454  uint32_t m;
+
3455  uint32_t n;
+
3456 
+
3457  if (handle == NULL) /* check handle */
+
3458  {
+
3459  return 2; /* return error */
+
3460  }
+
3461  if (handle->inited != 1) /* check handle initialization */
+
3462  {
+
3463  return 3; /* return error */
+
3464  }
+
3465 
+
3466  if (a_st7789_write_byte(handle, ST7789_CMD_CASET, ST7789_CMD) != 0) /* write set column address command */
+
3467  {
+
3468  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
3469 
+
3470  return 1; /* return error */
+
3471  }
+
3472  buf[0] = (0x00 >> 8) & 0xFF; /* start address msb */
+
3473  buf[1] = (0x00 >> 0) & 0xFF; /* start address lsb */
+
3474  buf[2] = ((handle->column - 1) >> 8) & 0xFF; /* end address msb */
+
3475  buf[3] = ((handle->column - 1) >> 0) & 0xFF; /* end address lsb */
+
3476  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
+
3477  {
+
3478  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3479 
+
3480  return 1; /* return error */
+
3481  }
+
3482 
+
3483  if (a_st7789_write_byte(handle, ST7789_CMD_RASET, ST7789_CMD) != 0) /* write set row address command */
+
3484  {
+
3485  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
3486 
+
3487  return 1; /* return error */
+
3488  }
+
3489  buf[0] = (0x00 >> 8) & 0xFF; /* start address msb */
+
3490  buf[1] = (0x00 >> 0) & 0xFF; /* start address lsb */
+
3491  buf[2] = ((handle->row - 1) >> 8) & 0xFF; /* end address msb */
+
3492  buf[3] = ((handle->row - 1) >> 0) & 0xFF; /* end address lsb */
+
3493  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
+
3494  {
+
3495  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3496 
+
3497  return 1; /* return error */
+
3498  }
+
3499 
+
3500  if (a_st7789_write_byte(handle, ST7789_CMD_RAMWR, ST7789_CMD) != 0) /* write memory write command */
+
3501  {
+
3502  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
3503 
+
3504  return 1; /* return error */
+
3505  }
+
3506 
+
3507  if ((handle->format & 0x03) == 0x03) /* rgb444 */
+
3508  {
+
3509  memset(handle->buf, 0x00, sizeof(uint8_t) * ST7789_BUFFER_SIZE); /* clear buffer */
+
3510  m = ((uint32_t)(handle->row) * handle->column * 3 / 2) /
+
3511  ST7789_BUFFER_SIZE; /* total times */
+
3512  n = ((uint32_t)(handle->row) * handle->column * 3 / 2) %
+
3513  ST7789_BUFFER_SIZE; /* the last */
+
3514  for (i = 0; i < m; i++)
+
3515  {
+
3516  if (a_st7789_write_bytes(handle, handle->buf,
+
3517  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
+
3518  {
+
3519  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3520 
+
3521  return 1; /* return error */
+
3522  }
+
3523  }
+
3524  if (n != 0) /* not end */
+
3525  {
+
3526  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
+
3527  {
+
3528  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3529 
+
3530  return 1; /* return error */
+
3531  }
+
3532  }
+
3533  }
+
3534  else if ((handle->format & 0x05) == 0x05) /* rgb565 */
+
3535  {
+
3536  memset(handle->buf, 0x00, sizeof(uint8_t) * ST7789_BUFFER_SIZE); /* clear buffer */
+
3537  m = (uint32_t)(handle->row) * handle->column * 2 / ST7789_BUFFER_SIZE; /* total times */
+
3538  n = (uint32_t)(handle->row) * handle->column * 2 % ST7789_BUFFER_SIZE; /* the last */
+
3539  for (i = 0; i < m; i++)
+
3540  {
+
3541  if (a_st7789_write_bytes(handle, handle->buf,
+
3542  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
+
3543  {
+
3544  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3545 
+
3546  return 1; /* return error */
+
3547  }
+
3548  }
+
3549  if (n != 0) /* not end */
+
3550  {
+
3551  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
+
3552  {
+
3553  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3554 
+
3555  return 1; /* return error */
+
3556  }
+
3557  }
+
3558  }
+
3559  else if ((handle->format & 0x06) == 0x06) /* rgb666 */
+
3560  {
+
3561  memset(handle->buf, 0x00, sizeof(uint8_t) * ST7789_BUFFER_SIZE); /* clear buffer */
+
3562  m = (uint32_t)(handle->row) * handle->column * 3 / ST7789_BUFFER_SIZE; /* total times */
+
3563  n = (uint32_t)(handle->row) * handle->column * 3 % ST7789_BUFFER_SIZE; /* the last */
+
3564  for (i = 0; i < m; i++)
+
3565  {
+
3566  if (a_st7789_write_bytes(handle, handle->buf,
+
3567  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
+
3568  {
+
3569  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3570 
+
3571  return 1; /* return error */
+
3572  }
+
3573  }
+
3574  if (n != 0) /* not end */
+
3575  {
+
3576  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
+
3577  {
+
3578  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3579 
+
3580  return 1; /* return error */
+
3581  }
+
3582  }
+
3583  }
+
3584  else
+
3585  {
+
3586  handle->debug_print("st7789: format is invalid.\n"); /* format is invalid */
+
3587 
+
3588  return 4; /* return error */
+
3589  }
+
3590 
+
3591  return 0; /* success return 0 */
+
3592 }
+
3593 
+
3615 uint8_t st7789_fill_rect(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint32_t color)
+
3616 {
+
3617  uint8_t buf[4];
+
3618  uint32_t i;
+
3619  uint32_t m;
+
3620  uint32_t n;
+
3621 
+
3622  if (handle == NULL) /* check handle */
+
3623  {
+
3624  return 2; /* return error */
+
3625  }
+
3626  if (handle->inited != 1) /* check handle initialization */
+
3627  {
+
3628  return 3; /* return error */
+
3629  }
+
3630  if (left > (handle->column - 1)) /* check left */
+
3631  {
+
3632  handle->debug_print("st7789: left is over column.\n"); /* left is over column */
+
3633 
+
3634  return 4; /* return error */
+
3635  }
+
3636  if (right > (handle->column - 1)) /* check right */
+
3637  {
+
3638  handle->debug_print("st7789: right is over column.\n"); /* right is over column */
+
3639 
+
3640  return 5; /* return error */
+
3641  }
+
3642  if (left >= right) /* check left and right */
+
3643  {
+
3644  handle->debug_print("st7789: left >= right.\n"); /* left >= right */
+
3645 
+
3646  return 6; /* return error */
+
3647  }
+
3648  if (top > (handle->row - 1)) /* check top */
+
3649  {
+
3650  handle->debug_print("st7789: top is over row.\n"); /* top is over row */
+
3651 
+
3652  return 7; /* return error */
+
3653  }
+
3654  if (bottom > (handle->row - 1)) /* check bottom */
+
3655  {
+
3656  handle->debug_print("st7789: bottom is over row.\n"); /* bottom is over row */
+
3657 
+
3658  return 8; /* return error */
+
3659  }
+
3660  if (top >= bottom) /* check top and bottom */
+
3661  {
+
3662  handle->debug_print("st7789: top >= bottom.\n"); /* top >= bottom */
+
3663 
+
3664  return 9; /* return error */
+
3665  }
+
3666 
+
3667  if (a_st7789_write_byte(handle, ST7789_CMD_CASET, ST7789_CMD) != 0) /* write set column address command */
+
3668  {
+
3669  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
3670 
+
3671  return 1; /* return error */
+
3672  }
+
3673  buf[0] = (left >> 8) & 0xFF; /* start address msb */
+
3674  buf[1] = (left >> 0) & 0xFF; /* start address lsb */
+
3675  buf[2] = ((right) >> 8) & 0xFF; /* end address msb */
+
3676  buf[3] = ((right) >> 0) & 0xFF; /* end address lsb */
+
3677  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
+
3678  {
+
3679  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3680 
+
3681  return 1; /* return error */
+
3682  }
+
3683 
+
3684  if (a_st7789_write_byte(handle, ST7789_CMD_RASET, ST7789_CMD) != 0) /* write set row address command */
+
3685  {
+
3686  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
3687 
+
3688  return 1; /* return error */
+
3689  }
+
3690  buf[0] = (top >> 8) & 0xFF; /* start address msb */
+
3691  buf[1] = (top >> 0) & 0xFF; /* start address lsb */
+
3692  buf[2] = ((bottom) >> 8) & 0xFF; /* end address msb */
+
3693  buf[3] = ((bottom) >> 0) & 0xFF; /* end address lsb */
+
3694  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
+
3695  {
+
3696  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3697 
+
3698  return 1; /* return error */
+
3699  }
+
3700 
+
3701  if (a_st7789_write_byte(handle, ST7789_CMD_RAMWR, ST7789_CMD) != 0) /* write memory write command */
+
3702  {
+
3703  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
3704 
+
3705  return 1; /* return error */
+
3706  }
+
3707 
+
3708  if ((handle->format & 0x03) == 0x03) /* rgb444 */
+
3709  {
+
3710  for (i = 0; i < ST7789_BUFFER_SIZE; i += 3) /* fill the buffer */
+
3711  {
+
3712  handle->buf[i] = (((color >> 8) & 0xF) << 4) |
+
3713  (((color >> 4) & 0xF) << 0); /* set the color */
+
3714  handle->buf[i + 1] = (((color >> 0) & 0xF) << 4) |
+
3715  (((color >> 8) & 0xF) << 0); /* set the color */
+
3716  handle->buf[i + 2] = (((color >> 4) & 0xF) << 4) |
+
3717  (((color >> 0) & 0xF) << 0); /* set the color */
+
3718  }
+
3719  m = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 3 / 2) /
+
3720  ST7789_BUFFER_SIZE; /* total times */
+
3721  n = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 3 / 2) %
+
3722  ST7789_BUFFER_SIZE; /* the last */
+
3723  for (i = 0; i < m; i++)
+
3724  {
+
3725  if (a_st7789_write_bytes(handle, handle->buf,
+
3726  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
+
3727  {
+
3728  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3729 
+
3730  return 1; /* return error */
+
3731  }
+
3732  }
+
3733  if (n != 0) /* not end */
+
3734  {
+
3735  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
+
3736  {
+
3737  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3738 
+
3739  return 1; /* return error */
+
3740  }
+
3741  }
+
3742  }
+
3743  else if ((handle->format & 0x05) == 0x05) /* rgb565 */
+
3744  {
+
3745  for (i = 0; i < ST7789_BUFFER_SIZE; i += 2) /* fill the buffer */
+
3746  {
+
3747  handle->buf[i] = (color >> 8) & 0xFF; /* set the color */
+
3748  handle->buf[i + 1] = (color >> 0) & 0xFF; /* set the color */
+
3749  }
+
3750  m = (uint32_t)(right - left + 1) * (bottom - top + 1) * 2 /
+
3751  ST7789_BUFFER_SIZE; /* total times */
+
3752  n = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 2) %
+
3753  ST7789_BUFFER_SIZE; /* the last */
+
3754  for (i = 0; i < m; i++)
+
3755  {
+
3756  if (a_st7789_write_bytes(handle, handle->buf,
+
3757  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
+
3758  {
+
3759  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3760 
+
3761  return 1; /* return error */
+
3762  }
+
3763  }
+
3764  if (n != 0) /* not end */
+
3765  {
+
3766  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
+
3767  {
+
3768  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3769 
+
3770  return 1; /* return error */
+
3771  }
+
3772  }
+
3773  }
+
3774  else if ((handle->format & 0x06) == 0x06) /* rgb666 */
+
3775  {
+
3776  for (i = 0; i < ST7789_BUFFER_SIZE; i += 3) /* fill the buffer */
+
3777  {
+
3778  handle->buf[i] = ((color >> 12) & 0x3F) << 2; /* set the color */
+
3779  handle->buf[i + 1] = ((color >> 6) & 0x3F) << 2; /* set the color */
+
3780  handle->buf[i + 2] = ((color >> 0) & 0x3F) << 2; /* set the color */
+
3781  }
+
3782  m = (uint32_t)(right - left + 1) * (bottom - top + 1) * 3 /
+
3783  ST7789_BUFFER_SIZE; /* total times */
+
3784  n = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 3) %
+
3785  ST7789_BUFFER_SIZE; /* the last */
+
3786  for (i = 0; i < m; i++)
+
3787  {
+
3788  if (a_st7789_write_bytes(handle, handle->buf,
+
3789  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
+
3790  {
+
3791  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3792 
+
3793  return 1; /* return error */
+
3794  }
+
3795  }
+
3796  if (n != 0) /* not end */
+
3797  {
+
3798  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
+
3799  {
+
3800  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3801 
+
3802  return 1; /* return error */
+
3803  }
+
3804  }
+
3805  }
+
3806  else
+
3807  {
+
3808  handle->debug_print("st7789: format is invalid.\n"); /* format is invalid */
+
3809 
+
3810  return 4; /* return error */
+
3811  }
+
3812 
+
3813  return 0; /* success return 0 */
+
3814 }
+
3815 
+
3837 uint8_t st7789_draw_picture_12bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint16_t *image)
+
3838 {
+
3839  uint8_t buf[4];
+
3840  uint32_t i;
+
3841  uint32_t j;
+
3842  uint32_t m;
+
3843  uint32_t n;
+
3844  uint32_t point;
+
3845 
+
3846  if (handle == NULL) /* check handle */
+
3847  {
+
3848  return 2; /* return error */
+
3849  }
+
3850  if (handle->inited != 1) /* check handle initialization */
+
3851  {
+
3852  return 3; /* return error */
+
3853  }
+
3854  if (left > (handle->column - 1)) /* check left */
+
3855  {
+
3856  handle->debug_print("st7789: left is over column.\n"); /* left is over column */
+
3857 
+
3858  return 4; /* return error */
+
3859  }
+
3860  if (right > (handle->column - 1)) /* check right */
+
3861  {
+
3862  handle->debug_print("st7789: right is over column.\n"); /* right is over column */
+
3863 
+
3864  return 5; /* return error */
+
3865  }
+
3866  if (left >= right) /* check left and right */
+
3867  {
+
3868  handle->debug_print("st7789: left >= right.\n"); /* left >= right */
+
3869 
+
3870  return 6; /* return error */
+
3871  }
+
3872  if (top > (handle->row - 1)) /* check top */
+
3873  {
+
3874  handle->debug_print("st7789: top is over row.\n"); /* top is over row */
+
3875 
+
3876  return 7; /* return error */
+
3877  }
+
3878  if (bottom > (handle->row - 1)) /* check bottom */
+
3879  {
+
3880  handle->debug_print("st7789: bottom is over row.\n"); /* bottom is over row */
+
3881 
+
3882  return 8; /* return error */
+
3883  }
+
3884  if (top >= bottom) /* check top and bottom */
+
3885  {
+
3886  handle->debug_print("st7789: top >= bottom.\n"); /* top >= bottom */
+
3887 
+
3888  return 9; /* return error */
+
3889  }
+
3890 
+
3891  if (a_st7789_write_byte(handle, ST7789_CMD_CASET, ST7789_CMD) != 0) /* write set column address command */
+
3892  {
+
3893  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
3894 
+
3895  return 1; /* return error */
+
3896  }
+
3897  buf[0] = (left >> 8) & 0xFF; /* start address msb */
+
3898  buf[1] = (left >> 0) & 0xFF; /* start address lsb */
+
3899  buf[2] = ((right) >> 8) & 0xFF; /* end address msb */
+
3900  buf[3] = ((right) >> 0) & 0xFF; /* end address lsb */
+
3901  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
+
3902  {
+
3903  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3904 
+
3905  return 1; /* return error */
+
3906  }
+
3907 
+
3908  if (a_st7789_write_byte(handle, ST7789_CMD_RASET, ST7789_CMD) != 0) /* write set row address command */
+
3909  {
+
3910  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
3911 
+
3912  return 1; /* return error */
+
3913  }
+
3914  buf[0] = (top >> 8) & 0xFF; /* start address msb */
+
3915  buf[1] = (top >> 0) & 0xFF; /* start address lsb */
+
3916  buf[2] = ((bottom) >> 8) & 0xFF; /* end address msb */
+
3917  buf[3] = ((bottom) >> 0) & 0xFF; /* end address lsb */
+
3918  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
+
3919  {
+
3920  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3921 
+
3922  return 1; /* return error */
+
3923  }
+
3924 
+
3925  if (a_st7789_write_byte(handle, ST7789_CMD_RAMWR, ST7789_CMD) != 0) /* write memory write command */
+
3926  {
+
3927  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
3928 
+
3929  return 1; /* return error */
+
3930  }
+
3931 
+
3932  if ((handle->format & 0x03) == 0x03) /* rgb444 */
+
3933  {
+
3934  uint16_t r;
+
3935  uint16_t c;
+
3936  uint16_t color;
+
3937 
+
3938  c = right - left + 1; /* column */
+
3939  r = bottom - top + 1; /* row */
+
3940  point = 0; /* image point init 0 */
+
3941  m = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 3 / 2) /
+
3942  ST7789_BUFFER_SIZE; /* total times */
+
3943  n = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 3 / 2) %
+
3944  ST7789_BUFFER_SIZE; /* the last */
+
3945  for (i = 0; i < m; i++)
+
3946  {
+
3947  for (j = 0; j < ST7789_BUFFER_SIZE; j += 3) /* fill the buffer */
+
3948  {
+
3949  color = image[(point % c) * r + (point / c)]; /* set color */
+
3950  handle->buf[i] = (((color >> 8) & 0xF) << 4) |
+
3951  (((color >> 4) & 0xF) << 0); /* set the color */
+
3952  handle->buf[i + 1] = (((color >> 0) & 0xF) << 4) |
+
3953  (((color >> 8) & 0xF) << 0); /* set the color */
+
3954  handle->buf[i + 2] = (((color >> 4) & 0xF) << 4) |
+
3955  (((color >> 0) & 0xF) << 0); /* set the color */
+
3956  point++; /* point++ */
+
3957  }
+
3958  if (a_st7789_write_bytes(handle, handle->buf,
+
3959  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
+
3960  {
+
3961  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3962 
+
3963  return 1; /* return error */
+
3964  }
+
3965  }
+
3966  if (n != 0) /* not end */
+
3967  {
+
3968  for (j = 0; j < n; j += 3) /* fill the buffer */
+
3969  {
+
3970  color = image[(point % c) * r + (point / c)]; /* set color */
+
3971  handle->buf[i] = (((color >> 8) & 0xF) << 4) |
+
3972  (((color >> 4) & 0xF) << 0); /* set the color */
+
3973  handle->buf[i + 1] = (((color >> 0) & 0xF) << 4) |
+
3974  (((color >> 8) & 0xF) << 0); /* set the color */
+
3975  handle->buf[i + 2] = (((color >> 4) & 0xF) << 4) |
+
3976  (((color >> 0) & 0xF) << 0); /* set the color */
+
3977  point++; /* point++ */
+
3978  }
+
3979  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
+
3980  {
+
3981  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
3982 
+
3983  return 1; /* return error */
+
3984  }
+
3985  }
+
3986  }
+
3987  else
+
3988  {
+
3989  handle->debug_print("st7789: format is invalid.\n"); /* format is invalid */
+
3990 
+
3991  return 4; /* return error */
+
3992  }
+
3993 
+
3994  return 0; /* success return 0 */
+
3995 }
+
3996 
+
4018 uint8_t st7789_draw_picture_16bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint16_t *image)
+
4019 {
+
4020  uint8_t buf[4];
+
4021  uint32_t i;
+
4022  uint32_t j;
+
4023  uint32_t m;
+
4024  uint32_t n;
+
4025  uint32_t point;
+
4026 
+
4027  if (handle == NULL) /* check handle */
+
4028  {
+
4029  return 2; /* return error */
+
4030  }
+
4031  if (handle->inited != 1) /* check handle initialization */
+
4032  {
+
4033  return 3; /* return error */
+
4034  }
+
4035  if (left > (handle->column - 1)) /* check left */
+
4036  {
+
4037  handle->debug_print("st7789: left is over column.\n"); /* left is over column */
+
4038 
+
4039  return 4; /* return error */
+
4040  }
+
4041  if (right > (handle->column - 1)) /* check right */
+
4042  {
+
4043  handle->debug_print("st7789: right is over column.\n"); /* right is over column */
+
4044 
+
4045  return 5; /* return error */
+
4046  }
+
4047  if (left >= right) /* check left and right */
+
4048  {
+
4049  handle->debug_print("st7789: left >= right.\n"); /* left >= right */
+
4050 
+
4051  return 6; /* return error */
+
4052  }
+
4053  if (top > (handle->row - 1)) /* check top */
+
4054  {
+
4055  handle->debug_print("st7789: top is over row.\n"); /* top is over row */
+
4056 
+
4057  return 7; /* return error */
+
4058  }
+
4059  if (bottom > (handle->row - 1)) /* check bottom */
+
4060  {
+
4061  handle->debug_print("st7789: bottom is over row.\n"); /* bottom is over row */
+
4062 
+
4063  return 8; /* return error */
+
4064  }
+
4065  if (top >= bottom) /* check top and bottom */
+
4066  {
+
4067  handle->debug_print("st7789: top >= bottom.\n"); /* top >= bottom */
+
4068 
+
4069  return 9; /* return error */
+
4070  }
+
4071 
+
4072  if (a_st7789_write_byte(handle, ST7789_CMD_CASET, ST7789_CMD) != 0) /* write set column address command */
+
4073  {
+
4074  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
4075 
+
4076  return 1; /* return error */
+
4077  }
+
4078  buf[0] = (left >> 8) & 0xFF; /* start address msb */
+
4079  buf[1] = (left >> 0) & 0xFF; /* start address lsb */
+
4080  buf[2] = ((right) >> 8) & 0xFF; /* end address msb */
+
4081  buf[3] = ((right) >> 0) & 0xFF; /* end address lsb */
+
4082  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
+
4083  {
+
4084  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
4085 
+
4086  return 1; /* return error */
+
4087  }
+
4088 
+
4089  if (a_st7789_write_byte(handle, ST7789_CMD_RASET, ST7789_CMD) != 0) /* write set row address command */
+
4090  {
+
4091  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
4092 
+
4093  return 1; /* return error */
+
4094  }
+
4095  buf[0] = (top >> 8) & 0xFF; /* start address msb */
+
4096  buf[1] = (top >> 0) & 0xFF; /* start address lsb */
+
4097  buf[2] = ((bottom) >> 8) & 0xFF; /* end address msb */
+
4098  buf[3] = ((bottom) >> 0) & 0xFF; /* end address lsb */
+
4099  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
+
4100  {
+
4101  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
4102 
+
4103  return 1; /* return error */
+
4104  }
+
4105 
+
4106  if (a_st7789_write_byte(handle, ST7789_CMD_RAMWR, ST7789_CMD) != 0) /* write memory write command */
+
4107  {
+
4108  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
4109 
+
4110  return 1; /* return error */
+
4111  }
+
4112 
+
4113  if ((handle->format & 0x05) == 0x05) /* rgb565 */
+
4114  {
+
4115  uint16_t r;
+
4116  uint16_t c;
+
4117  uint16_t color;
+
4118 
+
4119  c = right - left + 1; /* column */
+
4120  r = bottom - top + 1; /* row */
+
4121  point = 0; /* image point init 0 */
+
4122  m = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 2) /
+
4123  ST7789_BUFFER_SIZE; /* total times */
+
4124  n = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 2) %
+
4125  ST7789_BUFFER_SIZE; /* the last */
+
4126  for (i = 0; i < m; i++)
+
4127  {
+
4128  for (j = 0; j < ST7789_BUFFER_SIZE; j += 2) /* fill the buffer */
+
4129  {
+
4130  color = image[(point % c) * r + (point / c)]; /* set color */
+
4131  handle->buf[j] = (color >> 8) & 0xFF; /* set the color */
+
4132  handle->buf[j + 1] = (color >> 0) & 0xFF; /* set the color */
+
4133  point++; /* point++ */
+
4134  }
+
4135  if (a_st7789_write_bytes(handle, handle->buf,
+
4136  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
+
4137  {
+
4138  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
4139 
+
4140  return 1; /* return error */
+
4141  }
+
4142  }
+
4143  if (n != 0) /* not end */
+
4144  {
+
4145  for (j = 0; j < n; j += 2) /* fill the buffer */
+
4146  {
+
4147  color = image[(point % c) * r + (point / c)]; /* set color */
+
4148  handle->buf[j] = (color >> 8) & 0xFF; /* set the color */
+
4149  handle->buf[j + 1] = (color >> 0) & 0xFF; /* set the color */
+
4150  point++; /* point++ */
+
4151  }
+
4152  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
+
4153  {
+
4154  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
4155 
+
4156  return 1; /* return error */
+
4157  }
+
4158  }
+
4159  }
+
4160  else
+
4161  {
+
4162  handle->debug_print("st7789: format is invalid.\n"); /* format is invalid */
+
4163 
+
4164  return 4; /* return error */
+
4165  }
+
4166 
+
4167  return 0; /* success return 0 */
+
4168 }
+
4169 
+
4191 uint8_t st7789_draw_picture_18bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint32_t *image)
+
4192 {
+
4193  uint8_t buf[4];
+
4194  uint32_t i;
+
4195  uint32_t j;
+
4196  uint32_t m;
+
4197  uint32_t n;
+
4198  uint32_t point;
+
4199 
+
4200  if (handle == NULL) /* check handle */
+
4201  {
+
4202  return 2; /* return error */
+
4203  }
+
4204  if (handle->inited != 1) /* check handle initialization */
+
4205  {
+
4206  return 3; /* return error */
+
4207  }
+
4208  if (left > (handle->column - 1)) /* check left */
+
4209  {
+
4210  handle->debug_print("st7789: left is over column.\n"); /* left is over column */
+
4211 
+
4212  return 4; /* return error */
+
4213  }
+
4214  if (right > (handle->column - 1)) /* check right */
+
4215  {
+
4216  handle->debug_print("st7789: right is over column.\n"); /* right is over column */
+
4217 
+
4218  return 5; /* return error */
+
4219  }
+
4220  if (left >= right) /* check left and right */
+
4221  {
+
4222  handle->debug_print("st7789: left >= right.\n"); /* left >= right */
+
4223 
+
4224  return 6; /* return error */
+
4225  }
+
4226  if (top > (handle->row - 1)) /* check top */
+
4227  {
+
4228  handle->debug_print("st7789: top is over row.\n"); /* top is over row */
+
4229 
+
4230  return 7; /* return error */
+
4231  }
+
4232  if (bottom > (handle->row - 1)) /* check bottom */
+
4233  {
+
4234  handle->debug_print("st7789: bottom is over row.\n"); /* bottom is over row */
+
4235 
+
4236  return 8; /* return error */
+
4237  }
+
4238  if (top >= bottom) /* check top and bottom */
+
4239  {
+
4240  handle->debug_print("st7789: top >= bottom.\n"); /* top >= bottom */
+
4241 
+
4242  return 9; /* return error */
+
4243  }
+
4244 
+
4245  if (a_st7789_write_byte(handle, ST7789_CMD_CASET, ST7789_CMD) != 0) /* write set column address command */
+
4246  {
+
4247  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
4248 
+
4249  return 1; /* return error */
+
4250  }
+
4251  buf[0] = (left >> 8) & 0xFF; /* start address msb */
+
4252  buf[1] = (left >> 0) & 0xFF; /* start address lsb */
+
4253  buf[2] = ((right) >> 8) & 0xFF; /* end address msb */
+
4254  buf[3] = ((right) >> 0) & 0xFF; /* end address lsb */
+
4255  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
+
4256  {
+
4257  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
4258 
+
4259  return 1; /* return error */
+
4260  }
+
4261 
+
4262  if (a_st7789_write_byte(handle, ST7789_CMD_RASET, ST7789_CMD) != 0) /* write set row address command */
+
4263  {
+
4264  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
4265 
+
4266  return 1; /* return error */
+
4267  }
+
4268  buf[0] = (top >> 8) & 0xFF; /* start address msb */
+
4269  buf[1] = (top >> 0) & 0xFF; /* start address lsb */
+
4270  buf[2] = ((bottom) >> 8) & 0xFF; /* end address msb */
+
4271  buf[3] = ((bottom) >> 0) & 0xFF; /* end address lsb */
+
4272  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
+
4273  {
+
4274  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
4275 
+
4276  return 1; /* return error */
+
4277  }
+
4278 
+
4279  if (a_st7789_write_byte(handle, ST7789_CMD_RAMWR, ST7789_CMD) != 0) /* write memory write command */
+
4280  {
+
4281  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
4282 
+
4283  return 1; /* return error */
+
4284  }
+
4285 
+
4286  if ((handle->format & 0x06) == 0x06) /* rgb666 */
+
4287  {
+
4288  uint16_t r;
+
4289  uint16_t c;
+
4290  uint32_t color;
+
4291 
+
4292  c = right - left + 1; /* column */
+
4293  r = bottom - top + 1; /* row */
+
4294  point = 0; /* image point init 0 */
+
4295  m = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 3) /
+
4296  ST7789_BUFFER_SIZE; /* total times */
+
4297  n = ((uint32_t)(right - left + 1) * (bottom - top + 1) * 3) %
+
4298  ST7789_BUFFER_SIZE; /* the last */
+
4299  for (i = 0; i < m; i++)
+
4300  {
+
4301  for (j = 0; j < ST7789_BUFFER_SIZE; j += 3) /* fill the buffer */
+
4302  {
+
4303  color = image[(point % c) * r + (point / c)]; /* set color */
+
4304  handle->buf[j] = ((color >> 12) & 0x3F) << 2; /* set the color */
+
4305  handle->buf[j + 1] = ((color >> 6) & 0x3F) << 2; /* set the color */
+
4306  handle->buf[j + 2] = ((color >> 0) & 0x3F) << 2; /* set the color */
+
4307  point++; /* point++ */
+
4308  }
+
4309  if (a_st7789_write_bytes(handle, handle->buf,
+
4310  ST7789_BUFFER_SIZE, ST7789_DATA) != 0) /* write data */
+
4311  {
+
4312  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
4313 
+
4314  return 1; /* return error */
+
4315  }
+
4316  }
+
4317  if (n != 0) /* not end */
+
4318  {
+
4319  for (j = 0; j < n; j += 3) /* fill the buffer */
+
4320  {
+
4321  color = image[(point % c) * r + (point / c)]; /* set color */
+
4322  handle->buf[j] = ((color >> 12) & 0x3F) << 2; /* set the color */
+
4323  handle->buf[j + 1] = ((color >> 6) & 0x3F) << 2; /* set the color */
+
4324  handle->buf[j + 2] = ((color >> 0) & 0x3F) << 2; /* set the color */
+
4325  point++; /* point++ */
+
4326  }
+
4327  if (a_st7789_write_bytes(handle, handle->buf, n, ST7789_DATA) != 0) /* write data */
+
4328  {
+
4329  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
4330 
+
4331  return 1; /* return error */
+
4332  }
+
4333  }
+
4334  }
+
4335  else
+
4336  {
+
4337  handle->debug_print("st7789: format is invalid.\n"); /* format is invalid */
+
4338 
+
4339  return 4; /* return error */
+
4340  }
+
4341 
+
4342  return 0; /* success return 0 */
+
4343 }
+
4344 
+
4356 static uint8_t a_st7789_draw_point(st7789_handle_t *handle, uint16_t x, uint16_t y, uint32_t color)
+
4357 {
+
4358  uint8_t buf[4];
+
4359 
+
4360  if (a_st7789_write_byte(handle, ST7789_CMD_CASET, ST7789_CMD) != 0) /* write set column address command */
+
4361  {
+
4362  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
4363 
+
4364  return 1; /* return error */
+
4365  }
+
4366  buf[0] = (x >> 8) & 0xFF; /* start address msb */
+
4367  buf[1] = (x >> 0) & 0xFF; /* start address lsb */
+
4368  buf[2] = (x >> 8) & 0xFF; /* end address msb */
+
4369  buf[3] = (x >> 0) & 0xFF; /* end address lsb */
+
4370  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
+
4371  {
+
4372  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
4373 
+
4374  return 1; /* return error */
+
4375  }
+
4376 
+
4377  if (a_st7789_write_byte(handle, ST7789_CMD_RASET, ST7789_CMD) != 0) /* write set row address command */
+
4378  {
+
4379  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
4380 
+
4381  return 1; /* return error */
+
4382  }
+
4383  buf[0] = (y >> 8) & 0xFF; /* start address msb */
+
4384  buf[1] = (y >> 0) & 0xFF; /* start address lsb */
+
4385  buf[2] = (y >> 8) & 0xFF; /* end address msb */
+
4386  buf[3] = (y >> 0) & 0xFF; /* end address lsb */
+
4387  if (a_st7789_write_bytes(handle, buf, 4, ST7789_DATA) != 0) /* write data */
+
4388  {
+
4389  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
4390 
+
4391  return 1; /* return error */
+
4392  }
+
4393 
+
4394  if (a_st7789_write_byte(handle, ST7789_CMD_RAMWR, ST7789_CMD) != 0) /* write memory write command */
+
4395  {
+
4396  handle->debug_print("st7789: write command failed.\n"); /* write command failed */
+
4397 
+
4398  return 1; /* return error */
+
4399  }
+
4400 
+
4401  if ((handle->format & 0x03) == 0x03) /* rgb444 */
+
4402  {
+
4403  handle->buf[0] = (((color >> 8) & 0xF) << 4) |
+
4404  (((color >> 4) & 0xF) << 0); /* set the color */
+
4405  handle->buf[1] = (((color >> 0) & 0xF) << 4); /* set the color */
+
4406  if (a_st7789_write_bytes(handle, handle->buf,
+
4407  2, ST7789_DATA) != 0) /* write data */
+
4408  {
+
4409  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
4410 
+
4411  return 1; /* return error */
+
4412  }
+
4413  }
+
4414  else if ((handle->format & 0x05) == 0x05) /* rgb565 */
+
4415  {
+
4416  handle->buf[0] = (color >> 8) & 0xFF; /* set the color */
+
4417  handle->buf[1] = (color >> 0) & 0xFF; /* set the color */
+
4418  if (a_st7789_write_bytes(handle, handle->buf,
+
4419  2, ST7789_DATA) != 0) /* write data */
+
4420  {
+
4421  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
4422 
+
4423  return 1; /* return error */
+
4424  }
+
4425  }
+
4426  else if ((handle->format & 0x06) == 0x06) /* rgb666 */
+
4427  {
+
4428  handle->buf[0] = ((color >> 12) & 0x3F) << 2; /* set the color */
+
4429  handle->buf[1] = ((color >> 6) & 0x3F) << 2; /* set the color */
+
4430  handle->buf[2] = ((color >> 0) & 0x3F) << 2; /* set the color */
+
4431  if (a_st7789_write_bytes(handle, handle->buf,
+
4432  3, ST7789_DATA) != 0) /* write data */
+
4433  {
+
4434  handle->debug_print("st7789: write data failed.\n"); /* write data failed */
+
4435 
+
4436  return 1; /* return error */
+
4437  }
+
4438  }
+
4439  else
+
4440  {
+
4441  handle->debug_print("st7789: format is invalid.\n"); /* format is invalid */
+
4442 
+
4443  return 4; /* return error */
+
4444  }
+
4445 
+
4446  return 0; /* success return 0 */
+
4447 }
+
4448 
+
4462 static uint8_t a_st7789_show_char(st7789_handle_t *handle, uint16_t x, uint16_t y, uint8_t chr, uint8_t size, uint32_t color)
+
4463 {
+
4464  uint8_t temp, t, t1;
+
4465  uint16_t y0 = y;
+
4466  uint8_t csize = (size / 8 + ((size % 8) ? 1 : 0)) * (size / 2); /* get size */
+
4467 
+
4468  chr = chr - ' '; /* get index */
+
4469  for (t = 0; t < csize; t++) /* write size */
+
4470  {
+
4471  if (size == 12) /* if size 12 */
+
4472  {
+
4473  temp = gsc_st7789_ascii_1206[chr][t]; /* get ascii 1206 */
+
4474  }
+
4475  else if (size == 16) /* if size 16 */
+
4476  {
+
4477  temp = gsc_st7789_ascii_1608[chr][t]; /* get ascii 1608 */
+
4478  }
+
4479  else if(size == 24) /* if size 24 */
+
4480  {
+
4481  temp = gsc_st7789_ascii_2412[chr][t]; /* get ascii 2412 */
+
4482  }
+
4483  else
+
4484  {
+
4485  return 1; /* return error */
+
4486  }
+
4487  for (t1 = 0; t1 < 8; t1++) /* write one line */
+
4488  {
+
4489  if ((temp & 0x80) != 0) /* if 1 */
+
4490  {
+
4491  if (a_st7789_draw_point(handle, x, y, color) != 0) /* draw point */
+
4492  {
+
4493  return 1; /* return error */
+
4494  }
+
4495  }
+
4496  temp <<= 1; /* left shift 1 */
+
4497  y++;
+
4498  if ((y - y0) == size) /* reset size */
+
4499  {
+
4500  y = y0; /* set y */
+
4501  x++; /* x++ */
+
4502 
+
4503  break; /* break */
+
4504  }
+
4505  }
+
4506  }
+
4507 
+
4508  return 0; /* success return 0 */
+
4509 }
+
4510 
+
4528 uint8_t st7789_write_string(st7789_handle_t *handle, uint16_t x, uint16_t y, char *str, uint16_t len, uint32_t color, st7789_font_t font)
+
4529 {
+
4530  if (handle == NULL) /* check handle */
+
4531  {
+
4532  return 2; /* return error */
+
4533  }
+
4534  if (handle->inited != 1) /* check handle initialization */
+
4535  {
+
4536  return 3; /* return error */
+
4537  }
+
4538  if((x >= handle->column) || (y >= handle->row)) /* check x, y */
+
4539  {
+
4540  handle->debug_print("ssd1351: x or y is invalid.\n"); /* x or y is invalid */
+
4541 
+
4542  return 4; /* return error */
+
4543  }
+
4544 
+
4545  while ((len != 0) && (*str <= '~') && (*str >= ' ')) /* write all string */
+
4546  {
+
4547  if (x >= (handle->column - (font / 2))) /* check x point */
+
4548  {
+
4549  x = 0; /* set x */
+
4550  y += (uint8_t)font; /* set next row */
+
4551  }
+
4552  if (y >= (handle->row - font)) /* check y pont */
+
4553  {
+
4554  y = x = 0; /* reset to 0 */
+
4555  }
+
4556  if (a_st7789_show_char(handle, x, y, *str, font, color) != 0) /* show a char */
+
4557  {
+
4558  return 1; /* return error */
+
4559  }
+
4560  x += (uint8_t)(font / 2); /* x + font/2 */
+
4561  str++; /* str address++ */
+
4562  len--; /* str length-- */
+
4563  }
+
4564 
+
4565  return 0; /* success return 0 */
+
4566 }
+
4567 
+
4583 uint8_t st7789_draw_point(st7789_handle_t *handle, uint16_t x, uint16_t y, uint32_t color)
+
4584 {
+
4585  if (handle == NULL) /* check handle */
+
4586  {
+
4587  return 2; /* return error */
+
4588  }
+
4589  if (handle->inited != 1) /* check handle initialization */
+
4590  {
+
4591  return 3; /* return error */
+
4592  }
+
4593  if (x >= handle->column) /* check x */
+
4594  {
+
4595  handle->debug_print("ssd1351: x is over column.\n"); /* x is over column */
+
4596 
+
4597  return 4; /* return error */
+
4598  }
+
4599  if (y >= handle->row) /* check y */
+
4600  {
+
4601  handle->debug_print("ssd1351: y is over row.\n"); /* y is over row */
+
4602 
+
4603  return 5; /* return error */
+
4604  }
+
4605 
+
4606  return a_st7789_draw_point(handle, x, y, color); /* draw point */
+
4607 }
+
4608 
+
4620 uint8_t st7789_write_cmd(st7789_handle_t *handle, uint8_t cmd)
+
4621 {
+
4622  if (handle == NULL) /* check handle */
+
4623  {
+
4624  return 2; /* return error */
+
4625  }
+
4626  if (handle->inited != 1) /* check handle initialization */
+
4627  {
+
4628  return 3; /* return error */
+
4629  }
+
4630 
+
4631  return a_st7789_write_byte(handle, cmd, ST7789_CMD); /* write command */
+
4632 }
+
4633 
+
4645 uint8_t st7789_write_data(st7789_handle_t *handle, uint8_t data)
+
4646 {
+
4647  if (handle == NULL) /* check handle */
+
4648  {
+
4649  return 2; /* return error */
+
4650  }
+
4651  if (handle->inited != 1) /* check handle initialization */
+
4652  {
+
4653  return 3; /* return error */
+
4654  }
+
4655 
+
4656  return a_st7789_write_byte(handle, data, ST7789_DATA); /* write data */
+
4657 }
+
4658 
+
4667 uint8_t st7789_info(st7789_info_t *info)
+
4668 {
+
4669  if (info == NULL) /* check handle */
+
4670  {
+
4671  return 2; /* return error */
+
4672  }
+
4673 
+
4674  memset(info, 0, sizeof(st7789_info_t)); /* initialize st7789 info structure */
+
4675  strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
+
4676  strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
+
4677  strncpy(info->interface, "SPI", 8); /* copy interface name */
+
4678  info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
+
4679  info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
+
4680  info->max_current_ma = MAX_CURRENT; /* set maximum current */
+
4681  info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
+
4682  info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
+
4683  info->driver_version = DRIVER_VERSION; /* set driver version */
+
4684 
+
4685  return 0; /* success return 0 */
+
4686 }
ST7789_CMD_RAMWR
#define ST7789_CMD_RAMWR
Definition: driver_st7789.c:74
ST7789_CMD_GAMSET
#define ST7789_CMD_GAMSET
Definition: driver_st7789.c:69
ST7789_CMD_VCOMS
#define ST7789_CMD_VCOMS
Definition: driver_st7789.c:98
@@ -3754,38 +3755,38 @@
st7789_display_mode_t
st7789_display_mode_t
st7789 display mode enumeration definition
Definition: driver_st7789.h:186
st7789_display_inversion_off
uint8_t st7789_display_inversion_off(st7789_handle_t *handle)
display inversion off
Definition: driver_st7789.c:381
st7789_font_t
st7789_font_t
st7789 font size enumeration definition
Definition: driver_st7789.h:79
-
st7789_draw_picture_18bits
uint8_t st7789_draw_picture_18bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint32_t *image)
draw a picture
Definition: driver_st7789.c:4190
+
st7789_draw_picture_18bits
uint8_t st7789_draw_picture_18bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint32_t *image)
draw a picture
Definition: driver_st7789.c:4191
st7789_set_vertical_scrolling
uint8_t st7789_set_vertical_scrolling(st7789_handle_t *handle, uint16_t top_fixed_area, uint16_t scrolling_area, uint16_t bottom_fixed_area)
set vertical scrolling
Definition: driver_st7789.c:748
st7789_display_on
uint8_t st7789_display_on(st7789_handle_t *handle)
display on
Definition: driver_st7789.c:512
st7789_tearing_effect_line_on
uint8_t st7789_tearing_effect_line_on(st7789_handle_t *handle, st7789_tearing_effect_t effect)
tearing effect line on
Definition: driver_st7789.c:826
st7789_set_vertical_scroll_start_address
uint8_t st7789_set_vertical_scroll_start_address(st7789_handle_t *handle, uint16_t start_address)
set the vertical scroll start address
Definition: driver_st7789.c:903
st7789_init
uint8_t st7789_init(st7789_handle_t *handle)
initialize the chip
Definition: driver_st7789.c:3205
st7789_set_tear_scanline
uint8_t st7789_set_tear_scanline(st7789_handle_t *handle, uint16_t l)
set tear scanline
Definition: driver_st7789.c:1097
-
st7789_draw_picture_12bits
uint8_t st7789_draw_picture_12bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint16_t *image)
draw a picture
Definition: driver_st7789.c:3836
+
st7789_draw_picture_12bits
uint8_t st7789_draw_picture_12bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint16_t *image)
draw a picture
Definition: driver_st7789.c:3837
st7789_color_enhancement_mode_t
st7789_color_enhancement_mode_t
st7789 color enhancement mode enumeration definition
Definition: driver_st7789.h:147
st7789_set_column_address
uint8_t st7789_set_column_address(st7789_handle_t *handle, uint16_t start_address, uint16_t end_address)
set the column address
Definition: driver_st7789.c:547
ST7789_BUFFER_SIZE
#define ST7789_BUFFER_SIZE
st7789 buffer size definition
Definition: driver_st7789.h:63
-
st7789_set_row
uint8_t st7789_set_row(st7789_handle_t *handle, uint16_t row)
set row
Definition: driver_st7789.c:3416
+
st7789_set_row
uint8_t st7789_set_row(st7789_handle_t *handle, uint16_t row)
set row
Definition: driver_st7789.c:3417
st7789_normal_display_mode_on
uint8_t st7789_normal_display_mode_on(st7789_handle_t *handle)
normal display mode on
Definition: driver_st7789.c:350
-
st7789_write_string
uint8_t st7789_write_string(st7789_handle_t *handle, uint16_t x, uint16_t y, char *str, uint16_t len, uint32_t color, st7789_font_t font)
write a string in the display
Definition: driver_st7789.c:4527
+
st7789_write_string
uint8_t st7789_write_string(st7789_handle_t *handle, uint16_t x, uint16_t y, char *str, uint16_t len, uint32_t color, st7789_font_t font)
write a string in the display
Definition: driver_st7789.c:4528
st7789_software_reset
uint8_t st7789_software_reset(st7789_handle_t *handle)
software reset
Definition: driver_st7789.c:224
st7789_set_partial_areas
uint8_t st7789_set_partial_areas(st7789_handle_t *handle, uint16_t start_row, uint16_t end_row)
set partial areas
Definition: driver_st7789.c:702
st7789_rgb_interface_color_format_t
st7789_rgb_interface_color_format_t
st7789 rgb interface color format enumeration definition
Definition: driver_st7789.h:128
st7789_set_display_control
uint8_t st7789_set_display_control(st7789_handle_t *handle, st7789_bool_t brightness_control_block, st7789_bool_t display_dimming, st7789_bool_t backlight_control)
set display control
Definition: driver_st7789.c:1180
-
st7789_fill_rect
uint8_t st7789_fill_rect(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint32_t color)
fill the rect
Definition: driver_st7789.c:3614
+
st7789_fill_rect
uint8_t st7789_fill_rect(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint32_t color)
fill the rect
Definition: driver_st7789.c:3615
st7789_set_cabc_minimum_brightness
uint8_t st7789_set_cabc_minimum_brightness(st7789_handle_t *handle, uint8_t brightness)
set cabc minimum brightness
Definition: driver_st7789.c:1269
st7789_tearing_effect_line_off
uint8_t st7789_tearing_effect_line_off(st7789_handle_t *handle)
tearing effect line off
Definition: driver_st7789.c:794
st7789_set_interface_pixel_format
uint8_t st7789_set_interface_pixel_format(st7789_handle_t *handle, st7789_rgb_interface_color_format_t rgb, st7789_control_interface_color_format_t control)
set interface pixel format
Definition: driver_st7789.c:1014
st7789_idle_mode_off
uint8_t st7789_idle_mode_off(st7789_handle_t *handle)
idle mode off
Definition: driver_st7789.c:950
st7789_idle_mode_on
uint8_t st7789_idle_mode_on(st7789_handle_t *handle)
idle mode on
Definition: driver_st7789.c:981
-
st7789_deinit
uint8_t st7789_deinit(st7789_handle_t *handle)
close the chip
Definition: driver_st7789.c:3332
+
st7789_deinit
uint8_t st7789_deinit(st7789_handle_t *handle)
close the chip
Definition: driver_st7789.c:3333
st7789_nop
uint8_t st7789_nop(st7789_handle_t *handle)
nop
Definition: driver_st7789.c:193
st7789_partial_display_mode_on
uint8_t st7789_partial_display_mode_on(st7789_handle_t *handle)
partial display mode on
Definition: driver_st7789.c:319
st7789_set_brightness_control_and_color_enhancement
uint8_t st7789_set_brightness_control_and_color_enhancement(st7789_handle_t *handle, st7789_bool_t color_enhancement, st7789_color_enhancement_mode_t mode, st7789_color_enhancement_level_t level)
set brightness control and color enhancement
Definition: driver_st7789.c:1226
-
st7789_info
uint8_t st7789_info(st7789_info_t *info)
get chip's information
Definition: driver_st7789.c:4666
+
st7789_info
uint8_t st7789_info(st7789_info_t *info)
get chip's information
Definition: driver_st7789.c:4667
st7789_color_enhancement_level_t
st7789_color_enhancement_level_t
st7789 color enhancement level enumeration definition
Definition: driver_st7789.h:158
-
st7789_draw_picture_16bits
uint8_t st7789_draw_picture_16bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint16_t *image)
draw a picture
Definition: driver_st7789.c:4017
-
st7789_clear
uint8_t st7789_clear(st7789_handle_t *handle)
clear the display
Definition: driver_st7789.c:3449
+
st7789_draw_picture_16bits
uint8_t st7789_draw_picture_16bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint16_t *image)
draw a picture
Definition: driver_st7789.c:4018
+
st7789_clear
uint8_t st7789_clear(st7789_handle_t *handle)
clear the display
Definition: driver_st7789.c:3450
st7789_memory_continue_write
uint8_t st7789_memory_continue_write(st7789_handle_t *handle, uint8_t *data, uint16_t len)
memory continue write
Definition: driver_st7789.c:1059
st7789_display_off
uint8_t st7789_display_off(st7789_handle_t *handle)
display off
Definition: driver_st7789.c:481
st7789_bool_t
st7789_bool_t
st7789 bool enumeration definition
Definition: driver_st7789.h:70
@@ -3796,13 +3797,13 @@
st7789_set_gamma
uint8_t st7789_set_gamma(st7789_handle_t *handle, uint8_t gamma)
set gamma
Definition: driver_st7789.c:444
st7789_control_interface_color_format_t
st7789_control_interface_color_format_t
st7789 control interface color format enumeration definition
Definition: driver_st7789.h:137
st7789_set_display_brightness
uint8_t st7789_set_display_brightness(st7789_handle_t *handle, uint8_t brightness)
set display brightness
Definition: driver_st7789.c:1139
-
st7789_set_column
uint8_t st7789_set_column(st7789_handle_t *handle, uint16_t column)
set column
Definition: driver_st7789.c:3383
+
st7789_set_column
uint8_t st7789_set_column(st7789_handle_t *handle, uint16_t column)
set column
Definition: driver_st7789.c:3384
st7789_display_inversion_on
uint8_t st7789_display_inversion_on(st7789_handle_t *handle)
display inversion on
Definition: driver_st7789.c:412
-
st7789_draw_point
uint8_t st7789_draw_point(st7789_handle_t *handle, uint16_t x, uint16_t y, uint32_t color)
draw a point in the display
Definition: driver_st7789.c:4582
+
st7789_draw_point
uint8_t st7789_draw_point(st7789_handle_t *handle, uint16_t x, uint16_t y, uint32_t color)
draw a point in the display
Definition: driver_st7789.c:4583
st7789_sleep_out
uint8_t st7789_sleep_out(st7789_handle_t *handle)
sleep out
Definition: driver_st7789.c:287
st7789_set_memory_data_access_control
uint8_t st7789_set_memory_data_access_control(st7789_handle_t *handle, uint8_t order)
set memory data access control
Definition: driver_st7789.c:864
-
st7789_write_data
uint8_t st7789_write_data(st7789_handle_t *handle, uint8_t data)
write the data
Definition: driver_st7789.c:4644
-
st7789_write_cmd
uint8_t st7789_write_cmd(st7789_handle_t *handle, uint8_t cmd)
write the command
Definition: driver_st7789.c:4619
+
st7789_write_data
uint8_t st7789_write_data(st7789_handle_t *handle, uint8_t data)
write the data
Definition: driver_st7789.c:4645
+
st7789_write_cmd
uint8_t st7789_write_cmd(st7789_handle_t *handle, uint8_t cmd)
write the command
Definition: driver_st7789.c:4620
st7789_handle_s
st7789 handle structure definition
Definition: driver_st7789.h:557
st7789_handle_s::inited
uint8_t inited
Definition: driver_st7789.h:569
st7789_handle_s::spi_init
uint8_t(* spi_init)(void)
Definition: driver_st7789.h:558
diff --git a/doc/html/driver__st7789_8h_source.html b/doc/html/driver__st7789_8h_source.html index efe0ba4..3112231 100644 --- a/doc/html/driver__st7789_8h_source.html +++ b/doc/html/driver__st7789_8h_source.html @@ -999,40 +999,40 @@
ST7789_DISPLAY_MODE_MCU
@ ST7789_DISPLAY_MODE_MCU
Definition: driver_st7789.h:187
st7789_display_inversion_off
uint8_t st7789_display_inversion_off(st7789_handle_t *handle)
display inversion off
Definition: driver_st7789.c:381
st7789_font_t
st7789_font_t
st7789 font size enumeration definition
Definition: driver_st7789.h:79
-
st7789_draw_picture_18bits
uint8_t st7789_draw_picture_18bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint32_t *image)
draw a picture
Definition: driver_st7789.c:4190
+
st7789_draw_picture_18bits
uint8_t st7789_draw_picture_18bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint32_t *image)
draw a picture
Definition: driver_st7789.c:4191
st7789_set_vertical_scrolling
uint8_t st7789_set_vertical_scrolling(st7789_handle_t *handle, uint16_t top_fixed_area, uint16_t scrolling_area, uint16_t bottom_fixed_area)
set vertical scrolling
Definition: driver_st7789.c:748
st7789_display_on
uint8_t st7789_display_on(st7789_handle_t *handle)
display on
Definition: driver_st7789.c:512
st7789_tearing_effect_line_on
uint8_t st7789_tearing_effect_line_on(st7789_handle_t *handle, st7789_tearing_effect_t effect)
tearing effect line on
Definition: driver_st7789.c:826
st7789_set_vertical_scroll_start_address
uint8_t st7789_set_vertical_scroll_start_address(st7789_handle_t *handle, uint16_t start_address)
set the vertical scroll start address
Definition: driver_st7789.c:903
st7789_init
uint8_t st7789_init(st7789_handle_t *handle)
initialize the chip
Definition: driver_st7789.c:3205
st7789_set_tear_scanline
uint8_t st7789_set_tear_scanline(st7789_handle_t *handle, uint16_t l)
set tear scanline
Definition: driver_st7789.c:1097
-
st7789_draw_picture_12bits
uint8_t st7789_draw_picture_12bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint16_t *image)
draw a picture
Definition: driver_st7789.c:3836
+
st7789_draw_picture_12bits
uint8_t st7789_draw_picture_12bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint16_t *image)
draw a picture
Definition: driver_st7789.c:3837
st7789_color_enhancement_mode_t
st7789_color_enhancement_mode_t
st7789 color enhancement mode enumeration definition
Definition: driver_st7789.h:147
st7789_set_column_address
uint8_t st7789_set_column_address(st7789_handle_t *handle, uint16_t start_address, uint16_t end_address)
set the column address
Definition: driver_st7789.c:547
st7789_handle_t
struct st7789_handle_s st7789_handle_t
st7789 handle structure definition
ST7789_BUFFER_SIZE
#define ST7789_BUFFER_SIZE
st7789 buffer size definition
Definition: driver_st7789.h:63
-
st7789_set_row
uint8_t st7789_set_row(st7789_handle_t *handle, uint16_t row)
set row
Definition: driver_st7789.c:3416
+
st7789_set_row
uint8_t st7789_set_row(st7789_handle_t *handle, uint16_t row)
set row
Definition: driver_st7789.c:3417
st7789_normal_display_mode_on
uint8_t st7789_normal_display_mode_on(st7789_handle_t *handle)
normal display mode on
Definition: driver_st7789.c:350
-
st7789_write_string
uint8_t st7789_write_string(st7789_handle_t *handle, uint16_t x, uint16_t y, char *str, uint16_t len, uint32_t color, st7789_font_t font)
write a string in the display
Definition: driver_st7789.c:4527
+
st7789_write_string
uint8_t st7789_write_string(st7789_handle_t *handle, uint16_t x, uint16_t y, char *str, uint16_t len, uint32_t color, st7789_font_t font)
write a string in the display
Definition: driver_st7789.c:4528
st7789_software_reset
uint8_t st7789_software_reset(st7789_handle_t *handle)
software reset
Definition: driver_st7789.c:224
st7789_set_partial_areas
uint8_t st7789_set_partial_areas(st7789_handle_t *handle, uint16_t start_row, uint16_t end_row)
set partial areas
Definition: driver_st7789.c:702
st7789_rgb_interface_color_format_t
st7789_rgb_interface_color_format_t
st7789 rgb interface color format enumeration definition
Definition: driver_st7789.h:128
st7789_gamma_curve_t
st7789_gamma_curve_t
st7789 gamma curve enumeration definition
Definition: driver_st7789.h:89
st7789_set_display_control
uint8_t st7789_set_display_control(st7789_handle_t *handle, st7789_bool_t brightness_control_block, st7789_bool_t display_dimming, st7789_bool_t backlight_control)
set display control
Definition: driver_st7789.c:1180
-
st7789_fill_rect
uint8_t st7789_fill_rect(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint32_t color)
fill the rect
Definition: driver_st7789.c:3614
+
st7789_fill_rect
uint8_t st7789_fill_rect(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint32_t color)
fill the rect
Definition: driver_st7789.c:3615
st7789_set_cabc_minimum_brightness
uint8_t st7789_set_cabc_minimum_brightness(st7789_handle_t *handle, uint8_t brightness)
set cabc minimum brightness
Definition: driver_st7789.c:1269
st7789_tearing_effect_line_off
uint8_t st7789_tearing_effect_line_off(st7789_handle_t *handle)
tearing effect line off
Definition: driver_st7789.c:794
st7789_set_interface_pixel_format
uint8_t st7789_set_interface_pixel_format(st7789_handle_t *handle, st7789_rgb_interface_color_format_t rgb, st7789_control_interface_color_format_t control)
set interface pixel format
Definition: driver_st7789.c:1014
st7789_idle_mode_off
uint8_t st7789_idle_mode_off(st7789_handle_t *handle)
idle mode off
Definition: driver_st7789.c:950
st7789_idle_mode_on
uint8_t st7789_idle_mode_on(st7789_handle_t *handle)
idle mode on
Definition: driver_st7789.c:981
-
st7789_deinit
uint8_t st7789_deinit(st7789_handle_t *handle)
close the chip
Definition: driver_st7789.c:3332
+
st7789_deinit
uint8_t st7789_deinit(st7789_handle_t *handle)
close the chip
Definition: driver_st7789.c:3333
st7789_nop
uint8_t st7789_nop(st7789_handle_t *handle)
nop
Definition: driver_st7789.c:193
st7789_partial_display_mode_on
uint8_t st7789_partial_display_mode_on(st7789_handle_t *handle)
partial display mode on
Definition: driver_st7789.c:319
st7789_set_brightness_control_and_color_enhancement
uint8_t st7789_set_brightness_control_and_color_enhancement(st7789_handle_t *handle, st7789_bool_t color_enhancement, st7789_color_enhancement_mode_t mode, st7789_color_enhancement_level_t level)
set brightness control and color enhancement
Definition: driver_st7789.c:1226
-
st7789_info
uint8_t st7789_info(st7789_info_t *info)
get chip's information
Definition: driver_st7789.c:4666
+
st7789_info
uint8_t st7789_info(st7789_info_t *info)
get chip's information
Definition: driver_st7789.c:4667
st7789_color_enhancement_level_t
st7789_color_enhancement_level_t
st7789 color enhancement level enumeration definition
Definition: driver_st7789.h:158
-
st7789_draw_picture_16bits
uint8_t st7789_draw_picture_16bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint16_t *image)
draw a picture
Definition: driver_st7789.c:4017
-
st7789_clear
uint8_t st7789_clear(st7789_handle_t *handle)
clear the display
Definition: driver_st7789.c:3449
+
st7789_draw_picture_16bits
uint8_t st7789_draw_picture_16bits(st7789_handle_t *handle, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint16_t *image)
draw a picture
Definition: driver_st7789.c:4018
+
st7789_clear
uint8_t st7789_clear(st7789_handle_t *handle)
clear the display
Definition: driver_st7789.c:3450
st7789_memory_continue_write
uint8_t st7789_memory_continue_write(st7789_handle_t *handle, uint8_t *data, uint16_t len)
memory continue write
Definition: driver_st7789.c:1059
st7789_display_off
uint8_t st7789_display_off(st7789_handle_t *handle)
display off
Definition: driver_st7789.c:481
st7789_bool_t
st7789_bool_t
st7789 bool enumeration definition
Definition: driver_st7789.h:70
@@ -1044,10 +1044,10 @@
st7789_set_gamma
uint8_t st7789_set_gamma(st7789_handle_t *handle, uint8_t gamma)
set gamma
Definition: driver_st7789.c:444
st7789_control_interface_color_format_t
st7789_control_interface_color_format_t
st7789 control interface color format enumeration definition
Definition: driver_st7789.h:137
st7789_set_display_brightness
uint8_t st7789_set_display_brightness(st7789_handle_t *handle, uint8_t brightness)
set display brightness
Definition: driver_st7789.c:1139
-
st7789_set_column
uint8_t st7789_set_column(st7789_handle_t *handle, uint16_t column)
set column
Definition: driver_st7789.c:3383
+
st7789_set_column
uint8_t st7789_set_column(st7789_handle_t *handle, uint16_t column)
set column
Definition: driver_st7789.c:3384
st7789_display_inversion_on
uint8_t st7789_display_inversion_on(st7789_handle_t *handle)
display inversion on
Definition: driver_st7789.c:412
st7789_order_t
st7789_order_t
st7789 order enumeration definition
Definition: driver_st7789.h:109
-
st7789_draw_point
uint8_t st7789_draw_point(st7789_handle_t *handle, uint16_t x, uint16_t y, uint32_t color)
draw a point in the display
Definition: driver_st7789.c:4582
+
st7789_draw_point
uint8_t st7789_draw_point(st7789_handle_t *handle, uint16_t x, uint16_t y, uint32_t color)
draw a point in the display
Definition: driver_st7789.c:4583
st7789_sleep_out
uint8_t st7789_sleep_out(st7789_handle_t *handle)
sleep out
Definition: driver_st7789.c:287
st7789_set_memory_data_access_control
uint8_t st7789_set_memory_data_access_control(st7789_handle_t *handle, uint8_t order)
set memory data access control
Definition: driver_st7789.c:864
ST7789_FONT_24
@ ST7789_FONT_24
Definition: driver_st7789.h:82
@@ -1085,8 +1085,8 @@
ST7789_ORDER_PAGE_BOTTOM_TO_TOP
@ ST7789_ORDER_PAGE_BOTTOM_TO_TOP
Definition: driver_st7789.h:111
ST7789_ORDER_COLOR_RGB
@ ST7789_ORDER_COLOR_RGB
Definition: driver_st7789.h:118
ST7789_ORDER_PAGE_COLUMN_REVERSE
@ ST7789_ORDER_PAGE_COLUMN_REVERSE
Definition: driver_st7789.h:115
-
st7789_write_data
uint8_t st7789_write_data(st7789_handle_t *handle, uint8_t data)
write the data
Definition: driver_st7789.c:4644
-
st7789_write_cmd
uint8_t st7789_write_cmd(st7789_handle_t *handle, uint8_t cmd)
write the command
Definition: driver_st7789.c:4619
+
st7789_write_data
uint8_t st7789_write_data(st7789_handle_t *handle, uint8_t data)
write the data
Definition: driver_st7789.c:4645
+
st7789_write_cmd
uint8_t st7789_write_cmd(st7789_handle_t *handle, uint8_t cmd)
write the command
Definition: driver_st7789.c:4620
st7789_handle_s
st7789 handle structure definition
Definition: driver_st7789.h:557
st7789_handle_s::inited
uint8_t inited
Definition: driver_st7789.h:569
st7789_handle_s::spi_init
uint8_t(* spi_init)(void)
Definition: driver_st7789.h:558
diff --git a/doc/html/group__st7789__basic__driver.html b/doc/html/group__st7789__basic__driver.html index d331a13..c692862 100644 --- a/doc/html/group__st7789__basic__driver.html +++ b/doc/html/group__st7789__basic__driver.html @@ -657,7 +657,7 @@

Note
none
-

Definition at line 3449 of file driver_st7789.c.

+

Definition at line 3450 of file driver_st7789.c.

@@ -696,7 +696,7 @@

Note
none
-

Definition at line 3332 of file driver_st7789.c.

+

Definition at line 3333 of file driver_st7789.c.

@@ -921,7 +921,7 @@

Note
left <= column && right <= column && left < right && top <= row && bottom <= row && top < bottom
-

Definition at line 3836 of file driver_st7789.c.

+

Definition at line 3837 of file driver_st7789.c.

@@ -1002,7 +1002,7 @@

Note
left <= column && right <= column && left < right && top <= row && bottom <= row && top < bottom
-

Definition at line 4017 of file driver_st7789.c.

+

Definition at line 4018 of file driver_st7789.c.

@@ -1083,7 +1083,7 @@

Note
left <= column && right <= column && left < right && top <= row && bottom <= row && top < bottom
-

Definition at line 4190 of file driver_st7789.c.

+

Definition at line 4191 of file driver_st7789.c.

@@ -1146,7 +1146,7 @@

Note
x < column && y < row
-

Definition at line 4582 of file driver_st7789.c.

+

Definition at line 4583 of file driver_st7789.c.

@@ -1227,7 +1227,7 @@

Note
left <= column && right <= column && left < right && top <= row && bottom <= row && top < bottom
-

Definition at line 3614 of file driver_st7789.c.

+

Definition at line 3615 of file driver_st7789.c.

@@ -1333,7 +1333,7 @@

Note
none
-

Definition at line 4666 of file driver_st7789.c.

+

Definition at line 4667 of file driver_st7789.c.

@@ -1742,7 +1742,7 @@

Note
none
-

Definition at line 3383 of file driver_st7789.c.

+

Definition at line 3384 of file driver_st7789.c.

@@ -2155,7 +2155,7 @@

Note
none
-

Definition at line 3416 of file driver_st7789.c.

+

Definition at line 3417 of file driver_st7789.c.

@@ -2641,7 +2641,7 @@

Note
x < column && y < row
-

Definition at line 4527 of file driver_st7789.c.

+

Definition at line 4528 of file driver_st7789.c.

diff --git a/doc/html/group__st7789__extend__driver.html b/doc/html/group__st7789__extend__driver.html index 2f61de2..a979009 100644 --- a/doc/html/group__st7789__extend__driver.html +++ b/doc/html/group__st7789__extend__driver.html @@ -149,7 +149,7 @@

Note
none
-

Definition at line 4619 of file driver_st7789.c.

+

Definition at line 4620 of file driver_st7789.c.

@@ -196,7 +196,7 @@

Note
none
-

Definition at line 4644 of file driver_st7789.c.

+

Definition at line 4645 of file driver_st7789.c.

diff --git a/src/driver_st7789.c b/src/driver_st7789.c index 613b576..0755e5d 100644 --- a/src/driver_st7789.c +++ b/src/driver_st7789.c @@ -3294,7 +3294,7 @@ uint8_t st7789_init(st7789_handle_t *handle) return 4; /* return error */ } - handle->delay_ms(100); /* delay 100 ms */ + handle->delay_ms(25); /* over 10 us */ if (handle->reset_gpio_write(1) != 0) /* write 1 */ { handle->debug_print("st7789: reset gpio write failed.\n"); /* reset gpio write failed */ @@ -3303,6 +3303,7 @@ uint8_t st7789_init(st7789_handle_t *handle) return 4; /* return error */ } + handle->delay_ms(125); /* over 120 ms */ if (handle->spi_init() != 0) /* spi init */ { handle->debug_print("st7789: spi init failed.\n"); /* spi init failed */