DEV_Config.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /******************************************************************************
  2. **************************Hardware interface layer*****************************
  3. | file : DEV_Config.cpp
  4. | version : V1.0
  5. | date : 2020-06-16
  6. | function : Provide the hardware underlying interface
  7. ******************************************************************************/
  8. #include "DEV_Config.h"
  9. /********************************************************************************
  10. function: System Init and exit
  11. note:
  12. Initialize the communication method
  13. ********************************************************************************/
  14. uint8_t System_Init(void)
  15. {
  16. //set pin
  17. pinMode(OLED_CS, OUTPUT);
  18. pinMode(OLED_RST, OUTPUT);
  19. pinMode(OLED_DC, OUTPUT);
  20. //set Serial
  21. Serial.begin(115200);
  22. #if USE_SPI_4W
  23. Serial.println("USE_SPI");
  24. //set OLED SPI
  25. SPI.setDataMode(SPI_MODE3);
  26. SPI.setBitOrder(MSBFIRST);
  27. SPI.setClockDivider(SPI_CLOCK_DIV2);
  28. SPI.begin();
  29. #elif USE_IIC
  30. //set OLED I2C
  31. Serial.println("USE_I2C");
  32. OLED_DC_0;//DC = 1 => Address = 0x3d
  33. OLED_CS_0;
  34. Wire.setClock(1000000);
  35. Wire.begin();
  36. #endif
  37. return 0;
  38. }
  39. /********************************************************************************
  40. function: Hardware interface
  41. note:
  42. SPI4W_Write_Byte(value) :
  43. hardware SPI
  44. I2C_Write_Byte(value, cmd):
  45. hardware I2C
  46. ********************************************************************************/
  47. void SPI4W_Write_Byte(uint8_t DATA)
  48. {
  49. SPI.transfer(DATA);
  50. }
  51. void I2C_Write_Byte(uint8_t value, uint8_t Cmd)
  52. {
  53. uint8_t Addr = 0x3c;
  54. Wire.beginTransmission(Addr);
  55. Wire.write(Cmd);
  56. Wire.write(value);
  57. Wire.endTransmission();
  58. }
  59. /********************************************************************************
  60. function: Delay function
  61. note:
  62. Driver_Delay_ms(xms) : Delay x ms
  63. Driver_Delay_us(xus) : Delay x us
  64. ********************************************************************************/
  65. void Driver_Delay_ms(unsigned long xms)
  66. {
  67. delay(xms);
  68. }
  69. void Driver_Delay_us(int xus)
  70. {
  71. for (int j = xus; j > 0; j--);
  72. }