Browse Source

Base HAL SPI Changes

Christopher Pepper 7 years ago
parent
commit
a31e32969f
2 changed files with 14 additions and 12 deletions
  1. 3
    2
      Marlin/Sd2Card.cpp
  2. 11
    10
      Marlin/ultralcd_st7920_u8glib_rrd.h

+ 3
- 2
Marlin/Sd2Card.cpp View File

@@ -30,6 +30,7 @@
30 30
 
31 31
 #if ENABLED(SDSUPPORT)
32 32
 #include "Sd2Card.h"
33
+#include "src/HAL/spi_api.h"
33 34
 
34 35
 //------------------------------------------------------------------------------
35 36
 // send command and return error code.  Return zero for OK
@@ -89,14 +90,14 @@ uint32_t Sd2Card::cardSize() {
89 90
 }
90 91
 //------------------------------------------------------------------------------
91 92
 void Sd2Card::chipSelectHigh() {
92
-  digitalWrite(chipSelectPin_, HIGH);
93
+  HAL::SPI::disable_cs(SD_SPI_CHANNEL);
93 94
 }
94 95
 //------------------------------------------------------------------------------
95 96
 void Sd2Card::chipSelectLow() {
96 97
   #if DISABLED(SOFTWARE_SPI)
97 98
     spiInit(spiRate_);
98 99
   #endif  // SOFTWARE_SPI
99
-  digitalWrite(chipSelectPin_, LOW);
100
+  HAL::SPI::enable_cs(SD_SPI_CHANNEL);
100 101
 }
101 102
 //------------------------------------------------------------------------------
102 103
 /** Erase a range of blocks.

+ 11
- 10
Marlin/ultralcd_st7920_u8glib_rrd.h View File

@@ -105,21 +105,22 @@ static void ST7920_SWSPI_SND_8BIT(uint8_t val) {
105 105
   #define U8G_DELAY() u8g_10MicroDelay()
106 106
 #endif
107 107
 
108
-#define ST7920_CS()              { WRITE(ST7920_CS_PIN,1); U8G_DELAY(); }
109
-#define ST7920_NCS()             { WRITE(ST7920_CS_PIN,0); }
110
-#define ST7920_SET_CMD()         { ST7920_SWSPI_SND_8BIT(0xF8); U8G_DELAY(); }
111
-#define ST7920_SET_DAT()         { ST7920_SWSPI_SND_8BIT(0xFA); U8G_DELAY(); }
112
-#define ST7920_WRITE_BYTE(a)     { ST7920_SWSPI_SND_8BIT((uint8_t)((a)&0xF0u)); ST7920_SWSPI_SND_8BIT((uint8_t)((a)<<4u)); U8G_DELAY(); }
113
-#define ST7920_WRITE_BYTES(p,l)  { for (uint8_t i = l + 1; --i;) { ST7920_SWSPI_SND_8BIT(*p&0xF0); ST7920_SWSPI_SND_8BIT(*p<<4); p++; } U8G_DELAY(); }
108
+#include "src/HAL/spi_api.h"
109
+
110
+#define ST7920_CS()              { HAL::SPI::enable_cs(LCD_SPI_CHANNEL); U8G_DELAY();}
111
+#define ST7920_NCS()             { HAL::SPI::disable_cs(LCD_SPI_CHANNEL); }
112
+#define ST7920_SET_CMD()         { HAL::SPI::write(LCD_SPI_CHANNEL, 0xF8); U8G_DELAY(); }
113
+#define ST7920_SET_DAT()         { HAL::SPI::write(LCD_SPI_CHANNEL, 0xFA); U8G_DELAY(); }
114
+#define ST7920_WRITE_BYTE(a)     { HAL::SPI::write(LCD_SPI_CHANNEL, (uint8_t)((a)&0xF0u)); HAL::SPI::write(LCD_SPI_CHANNEL, (uint8_t)((a)<<4u)); U8G_DELAY(); }
115
+#define ST7920_WRITE_BYTES(p,l)  { for (uint8_t j = l + 1; --j;) { HAL::SPI::write(LCD_SPI_CHANNEL, *p&0xF0); HAL::SPI::write(LCD_SPI_CHANNEL, *p<<4); p++; } U8G_DELAY(); }
116
+
114 117
 
115 118
 uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
116 119
   uint8_t i, y;
117 120
   switch (msg) {
118 121
     case U8G_DEV_MSG_INIT: {
119
-      OUT_WRITE(ST7920_CS_PIN, LOW);
120
-      OUT_WRITE(ST7920_DAT_PIN, LOW);
121
-      OUT_WRITE(ST7920_CLK_PIN, HIGH);
122
-
122
+      HAL::SPI::initialise(LCD_SPI_CHANNEL);
123
+      HAL::SPI::set_frequency(LCD_SPI_CHANNEL, LCD_SPI_FREQUENCY);
123 124
       ST7920_CS();
124 125
       u8g_Delay(120);                 //initial delay for boot up
125 126
       ST7920_SET_CMD();

Loading…
Cancel
Save