DEV_Config.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*****************************************************************************
  2. * | File : DEV_Config.c
  3. * | Author : Waveshare team
  4. * | Function : Hardware underlying interface
  5. * | Info :
  6. * Used to shield the underlying layers of each master
  7. * and enhance portability
  8. *----------------
  9. * | This version: V2.0
  10. * | Date : 2018-10-30
  11. * | Info :
  12. # ******************************************************************************
  13. # Permission is hereby granted, free of charge, to any person obtaining a copy
  14. # of this software and associated documnetation files (the "Software"), to deal
  15. # in the Software without restriction, including without limitation the rights
  16. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  17. # copies of the Software, and to permit persons to whom the Software is
  18. # furished to do so, subject to the following conditions:
  19. #
  20. # The above copyright notice and this permission notice shall be included in
  21. # all copies or substantial portions of the Software.
  22. #
  23. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  29. # THE SOFTWARE.
  30. #
  31. ******************************************************************************/
  32. #include "DEV_Config.h"
  33. void DEV_SPI_WriteByte(UBYTE value)
  34. {
  35. if (econf.port == LUAT_EINK_SPI_DEVICE){
  36. luat_spi_device_send((luat_spi_device_t*)(econf.eink_spi_device), (const char *)&value, 1);
  37. }else{
  38. luat_spi_send(econf.port, (const char*)&value, 1);
  39. }
  40. }
  41. int DEV_Digital_Write(int pin, int level){
  42. if (pin == EPD_CS_PIN && econf.port == LUAT_EINK_SPI_DEVICE){
  43. return 0;
  44. }
  45. return luat_gpio_set(pin, level);
  46. }
  47. void EPD_Busy_WaitUntil(uint8_t level,uint8_t send_cmd){
  48. uint16_t count = 300;//30s
  49. while(1){
  50. if (level){
  51. if (send_cmd){
  52. DEV_Digital_Write(EPD_DC_PIN, 0);
  53. DEV_Digital_Write(EPD_CS_PIN, 0);
  54. DEV_SPI_WriteByte(0x71);
  55. DEV_Digital_Write(EPD_CS_PIN, 1);
  56. }
  57. if(DEV_Digital_Read(EPD_BUSY_PIN))
  58. break;
  59. }else{
  60. if(DEV_Digital_Read(EPD_BUSY_PIN)==0)
  61. break;
  62. }
  63. if(!(count--)){
  64. Debug("error: e-Paper busy timeout!!!\r\n");
  65. return;
  66. }
  67. else
  68. DEV_Delay_ms(100);
  69. }
  70. DEV_Delay_ms(100);
  71. }