Browse Source

Revert "SPI API platform implementation stubs" (#7416)

This reverts commit 2dfa6ca72a.

Revert "Base HAL SPI Changes"

This reverts commit 2afc521b8b.

Revert "Initial HAL SPI API"

This reverts commit 58f7ffe09a.
Chris Pepper 8 years ago
parent
commit
61c0a10efe

+ 2
- 3
Marlin/Sd2Card.cpp View File

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

+ 0
- 51
Marlin/src/HAL/HAL_AVR/spi_impl.cpp View File

@@ -1,51 +0,0 @@
1
-#ifdef ARDUINO_ARCH_AVR
2
-
3
-#include <stdint.h>
4
-
5
-namespace HAL {
6
-namespace SPI {
7
-
8
-bool initialise(uint8_t channel) {
9
-  return false;
10
-}
11
-
12
-bool enable_cs(uint8_t channel) {
13
-  return false;
14
-}
15
-
16
-void disable_cs(uint8_t channel) {
17
-
18
-}
19
-
20
-void set_frequency(uint8_t channel, uint32_t frequency) {
21
-
22
-}
23
-
24
-void read(uint8_t channel, uint8_t *buffer, uint32_t length) {
25
-
26
-}
27
-
28
-uint8_t read(uint8_t channel) {
29
-  return '\0';
30
-}
31
-
32
-void write(uint8_t channel, const uint8_t *buffer, uint32_t length) {
33
-
34
-}
35
-
36
-void write(uint8_t channel, uint8_t value) {
37
-
38
-}
39
-
40
-void transfer(uint8_t channel, const uint8_t *buffer_write, uint8_t *buffer_read, uint32_t length) {
41
-
42
-}
43
-
44
-uint8_t transfer(uint8_t channel, uint8_t value) {
45
-  return '\0';
46
-}
47
-
48
-} // namespace SPI
49
-} // namespace HAL
50
-
51
-#endif //#ifdef ARDUINO_ARCH_AVR

+ 0
- 4
Marlin/src/HAL/HAL_AVR/spi_pins.h View File

@@ -20,10 +20,6 @@
20 20
 #ifndef SPI_PINS_H_
21 21
 #define SPI_PINS_H_
22 22
 
23
-#define SD_SPI_CHANNEL (HAL::SPI::CHANNEL_0)
24
-#define LCD_SPI_FREQUENCY 4000000
25
-#define LCD_SPI_CHANNEL (HAL::SPI::CHANNEL_1)
26
-
27 23
 /**
28 24
  * Define SPI Pins: SCK, MISO, MOSI, SS
29 25
  */

+ 0
- 51
Marlin/src/HAL/HAL_DUE/spi_impl.cpp View File

@@ -1,51 +0,0 @@
1
-#ifdef ARDUINO_ARCH_SAM
2
-
3
-#include <stdint.h>
4
-
5
-namespace HAL {
6
-namespace SPI {
7
-
8
-bool initialise(uint8_t channel) {
9
-  return false;
10
-}
11
-
12
-bool enable_cs(uint8_t channel) {
13
-  return false;
14
-}
15
-
16
-void disable_cs(uint8_t channel) {
17
-
18
-}
19
-
20
-void set_frequency(uint8_t channel, uint32_t frequency) {
21
-
22
-}
23
-
24
-void read(uint8_t channel, uint8_t *buffer, uint32_t length) {
25
-
26
-}
27
-
28
-uint8_t read(uint8_t channel) {
29
-  return '\0';
30
-}
31
-
32
-void write(uint8_t channel, const uint8_t *buffer, uint32_t length) {
33
-
34
-}
35
-
36
-void write(uint8_t channel, uint8_t value) {
37
-
38
-}
39
-
40
-void transfer(uint8_t channel, const uint8_t *buffer_write, uint8_t *buffer_read, uint32_t length) {
41
-
42
-}
43
-
44
-uint8_t transfer(uint8_t channel, uint8_t value) {
45
-  return '\0';
46
-}
47
-
48
-} // namespace SPI
49
-} // namespace HAL
50
-
51
-#endif //#ifdef ARDUINO_ARCH_AVR

+ 0
- 5
Marlin/src/HAL/HAL_DUE/spi_pins.h View File

@@ -21,11 +21,6 @@
21 21
 #ifndef SPI_PINS_H_
22 22
 #define SPI_PINS_H_
23 23
 
24
-//new config options
25
-#define SD_SPI_CHANNEL (HAL::SPI::CHANNEL_0)
26
-#define LCD_SPI_FREQUENCY 4000000
27
-#define LCD_SPI_CHANNEL (HAL::SPI::CHANNEL_1)
28
-
29 24
 /**
30 25
  * Define SPI Pins: SCK, MISO, MOSI, SS
31 26
  *

+ 16
- 9
Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp View File

@@ -37,12 +37,12 @@
37 37
 // --------------------------------------------------------------------------
38 38
 
39 39
 #include "../../../MarlinConfig.h"
40
-#include "../spi_api.h"
41 40
 
42 41
 // --------------------------------------------------------------------------
43 42
 // Public Variables
44 43
 // --------------------------------------------------------------------------
45 44
 
45
+
46 46
 // --------------------------------------------------------------------------
47 47
 // Public functions
48 48
 // --------------------------------------------------------------------------
@@ -138,32 +138,39 @@
138 138
   }
139 139
 #else
140 140
   void spiBegin() {
141
-    HAL::SPI::initialise(SD_SPI_CHANNEL);
142 141
   }
143 142
 
144 143
   void spiInit(uint8_t spiRate) {
145
-    uint32_t freq =  8000000 / (1u << spiRate);
146
-    HAL::SPI::set_frequency(SD_SPI_CHANNEL, freq);
147 144
   }
148 145
 
149 146
   void spiSend(byte b) {
150
-    HAL::SPI::write(SD_SPI_CHANNEL, b);
147
+  }
148
+
149
+  void spiSend(const uint8_t* buf, size_t n) {
150
+  }
151
+
152
+  void spiSend(uint32_t chan, byte b) {
153
+  }
154
+
155
+  void spiSend(uint32_t chan, const uint8_t* buf, size_t n) {
156
+
151 157
   }
152 158
 
153 159
   // Read single byte from SPI
154 160
   uint8_t spiRec() {
155
-    return HAL::SPI::read(SD_SPI_CHANNEL);
161
+    return 0;
162
+  }
163
+
164
+  uint8_t spiRec(uint32_t chan) {
165
+    return 0;
156 166
   }
157 167
 
158 168
   // Read from SPI into buffer
159 169
   void spiRead(uint8_t*buf, uint16_t nbyte) {
160
-    HAL::SPI::read(SD_SPI_CHANNEL, buf, nbyte);
161 170
   }
162 171
 
163 172
   // Write from buffer to SPI
164 173
   void spiSendBlock(uint8_t token, const uint8_t* buf) {
165
-    HAL::SPI::write(SD_SPI_CHANNEL, token);
166
-    HAL::SPI::write(SD_SPI_CHANNEL, buf, 512);
167 174
   }
168 175
 #endif // ENABLED(SOFTWARE_SPI)
169 176
 

+ 3
- 2
Marlin/src/HAL/HAL_LPC1768/main.cpp View File

@@ -43,6 +43,7 @@ static __INLINE uint32_t SysTick_Config(uint32_t ticks) {
43 43
   SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
44 44
   return (0); /* Function successful */
45 45
 }
46
+
46 47
 extern "C" {
47 48
 extern void disk_timerproc(void);
48 49
 volatile uint32_t _millis;
@@ -69,7 +70,6 @@ extern "C" void SystemPostInit() {
69 70
 extern uint32_t MSC_SD_Init(uint8_t pdrv);
70 71
 extern HalSerial usb_serial;
71 72
 int main(void) {
72
-  debug_frmwrk_init();
73 73
 
74 74
   (void)MSC_SD_Init(0);
75 75
   USB_Init();                               // USB Initialization
@@ -81,7 +81,8 @@ int main(void) {
81 81
     TOGGLE(13);     // Flash fast while USB initialisation completes
82 82
   }
83 83
 
84
-  usb_serial.printf("\n\nRe-ARM (LPC1768 @ %dMhz) USB Initialised\n", SystemCoreClock / 1000000);
84
+  debug_frmwrk_init();
85
+  usb_serial.printf("\n\nRe-ARM (LPC1768 @ %dMhz) UART0 Initialised\n", SystemCoreClock / 1000000);
85 86
 
86 87
   HAL_timer_init();
87 88
 

+ 0
- 402
Marlin/src/HAL/HAL_LPC1768/spi_impl.cpp View File

@@ -1,402 +0,0 @@
1
-#ifdef TARGET_LPC1768
2
-
3
-#include "../spi_api.h"
4
-
5
-#include <lpc17xx_ssp.h>
6
-#include <lpc17xx_pinsel.h>
7
-#include <lpc17xx_gpio.h>
8
-#include "lpc17xx_clkpwr.h"
9
-
10
-extern "C" void SSP0_IRQHandler(void);
11
-extern "C" void SSP1_IRQHandler(void);
12
-
13
-namespace HAL {
14
-namespace SPI {
15
-
16
-enum class SignalPolarity : uint8_t {
17
-  ACTIVE_LOW = 0,
18
-  ACTIVE_HIGH
19
-};
20
-
21
-/* Hardware channels :
22
- * 0: clk(0_7),  mosi(0_9),  miso(0_8),  SSP1
23
- * 1: clk(0_15), mosi(0_28), miso(0_17), SSP0
24
-
25
- * Logical channels:
26
- * 0: hwchannel: 1, ssel(0_6)
27
- * 1: hwchannel: 0, ssel(0_16)
28
- * 2: hwchannel: 0, ssel(1_23)
29
- */
30
-
31
-/*
32
- * Defines the Hardware setup for an SPI channel
33
- * The pins and (if applicable) the Hardware Peripheral
34
- *
35
- */
36
-struct LogicalChannel; // who doesn't like circular dependencies
37
-
38
-struct HardwareChannel {
39
-  LPC_SSP_TypeDef *peripheral;
40
-  IRQn_Type IRQn;
41
-  uint8_t clk_port;
42
-  uint8_t clk_pin;
43
-  uint8_t mosi_port;
44
-  uint8_t mosi_pin;
45
-  uint8_t miso_port;
46
-  uint8_t miso_pin;
47
-  SSP_DATA_SETUP_Type xfer_config;
48
-  volatile FlagStatus xfer_complete;
49
-  bool initialised;
50
-  volatile bool in_use;
51
-  LogicalChannel* active_channel;
52
-} hardware_channels[2] = {
53
-    {LPC_SSP0, SSP0_IRQn, 0, 15, 0, 18, 0, 17, { nullptr, 0, nullptr, 0, 0, SSP_STAT_DONE }, RESET, false, false, nullptr},
54
-    {LPC_SSP1, SSP1_IRQn, 0, 7,  0, 9,  0, 8 , { nullptr, 0, nullptr, 0, 0, SSP_STAT_DONE }, RESET, false, false, nullptr}
55
-};
56
-
57
-/*
58
- * Define all available logical SPI ports
59
- */
60
-struct LogicalChannel {
61
-  HardwareChannel& hw_channel;
62
-  uint8_t ssel_port;
63
-  uint8_t ssel_pin;
64
-  SignalPolarity ssel_polarity;
65
-  bool ssel_override;
66
-  SSP_CFG_Type config;
67
-  uint32_t CR0;
68
-  uint32_t CPSR;
69
-} logical_channels[3] = {
70
-    { hardware_channels[1], 0, 6,  SignalPolarity::ACTIVE_LOW, false, { SSP_DATABIT_8, SSP_CPHA_FIRST, SSP_CPOL_HI, SSP_MASTER_MODE, SSP_FRAME_SPI, 1000000 }, 0, 0 },
71
-    { hardware_channels[0], 0, 16, SignalPolarity::ACTIVE_HIGH, true, { SSP_DATABIT_8, SSP_CPHA_FIRST, SSP_CPOL_HI, SSP_MASTER_MODE, SSP_FRAME_SPI, 1000000 }, 0, 0 },
72
-    { hardware_channels[0], 1, 23, SignalPolarity::ACTIVE_LOW, true, { SSP_DATABIT_8, SSP_CPHA_FIRST, SSP_CPOL_HI, SSP_MASTER_MODE, SSP_FRAME_SPI, 1000000 }, 0, 0 }
73
-};
74
-
75
-//Internal functions
76
-extern "C" void ssp_irq_handler(uint8_t hw_channel);
77
-LogicalChannel* get_logical_channel(uint8_t channel);
78
-bool set_ssel(LogicalChannel* logical_channel);
79
-void clear_ssel(LogicalChannel* logical_channel);
80
-void restore_frequency(LogicalChannel* logical_channel);
81
-
82
-LogicalChannel* get_logical_channel(uint8_t channel) {
83
-  if(channel > sizeof(logical_channels) - 1) {
84
-    return nullptr;
85
-  }
86
-  return &logical_channels[channel];
87
-}
88
-
89
-bool set_ssel(LogicalChannel* logical_channel) {
90
-  if(logical_channel->hw_channel.in_use == true) {
91
-    return false;
92
-  }
93
-
94
-  if(logical_channel->ssel_polarity == SignalPolarity::ACTIVE_HIGH) {
95
-    GPIO_SetValue(logical_channel->ssel_port, (1 << logical_channel->ssel_pin));
96
-  } else {
97
-    GPIO_ClearValue(logical_channel->ssel_port, (1 << logical_channel->ssel_pin));
98
-  }
99
-  logical_channel->hw_channel.in_use = true;
100
-
101
-  return true;
102
-}
103
-
104
-void clear_ssel(LogicalChannel* logical_channel) {
105
-  if(logical_channel->ssel_polarity == SignalPolarity::ACTIVE_HIGH) {
106
-    GPIO_ClearValue(logical_channel->ssel_port, (1 << logical_channel->ssel_pin));
107
-  } else {
108
-    GPIO_SetValue(logical_channel->ssel_port, (1 << logical_channel->ssel_pin));
109
-  }
110
-  logical_channel->hw_channel.in_use = false;
111
-}
112
-
113
-void restore_frequency(LogicalChannel* logical_channel) {
114
-  logical_channel->hw_channel.peripheral->CR0 = logical_channel->CR0;
115
-  logical_channel->hw_channel.peripheral->CPSR = logical_channel->CPSR;
116
-}
117
-
118
-/*
119
- * SPI API Implementation
120
- */
121
-bool initialise(uint8_t channel) {
122
-  LogicalChannel* logical_channel = get_logical_channel(channel);
123
-  if(logical_channel == nullptr) return false;
124
-  HardwareChannel& hw_channel = logical_channel->hw_channel;
125
-
126
-  PINSEL_CFG_Type pin_cfg;
127
-  pin_cfg.OpenDrain = PINSEL_PINMODE_NORMAL;
128
-  pin_cfg.Pinmode = PINSEL_PINMODE_PULLUP;
129
-
130
-  if(hw_channel.initialised == false) {
131
-    pin_cfg.Funcnum = 2; //ssp (spi) function
132
-    pin_cfg.Portnum = hw_channel.clk_port;
133
-    pin_cfg.Pinnum = hw_channel.clk_pin;
134
-    PINSEL_ConfigPin(&pin_cfg); //clk
135
-
136
-    pin_cfg.Portnum = hw_channel.miso_port;
137
-    pin_cfg.Pinnum = hw_channel.miso_pin;
138
-    PINSEL_ConfigPin(&pin_cfg); //miso
139
-
140
-    pin_cfg.Portnum = hw_channel.mosi_port;
141
-    pin_cfg.Pinnum = hw_channel.mosi_pin;
142
-    PINSEL_ConfigPin(&pin_cfg); //mosi
143
-
144
-    SSP_Init(hw_channel.peripheral, &logical_channel->config);
145
-    logical_channel->CR0 = logical_channel->hw_channel.peripheral->CR0; // preserve for restore
146
-    logical_channel->CPSR = logical_channel->hw_channel.peripheral->CPSR; // preserve for restore
147
-    SSP_Cmd(hw_channel.peripheral, ENABLE);
148
-
149
-    hw_channel.initialised = true;
150
-    hw_channel.active_channel = logical_channel;
151
-
152
-    //NVIC_SetPriority(hw_channel.IRQn, NVIC_EncodePriority(0, 3, 0)); //Very Low priority
153
-    //NVIC_EnableIRQ(hw_channel.IRQn);
154
-  }
155
-
156
-  pin_cfg.Portnum = logical_channel->ssel_port;
157
-  pin_cfg.Pinnum = logical_channel->ssel_pin;
158
-  pin_cfg.Pinmode = logical_channel->ssel_polarity ==  SignalPolarity::ACTIVE_LOW ? PINSEL_PINMODE_PULLUP : PINSEL_PINMODE_PULLDOWN;
159
-  pin_cfg.Funcnum = 0; //gpio function
160
-  PINSEL_ConfigPin(&pin_cfg); //ssel
161
-
162
-  GPIO_SetDir(logical_channel->ssel_port, (1 << logical_channel->ssel_pin), 1);
163
-  GPIO_SetValue(logical_channel->ssel_port, (1 << logical_channel->ssel_pin));
164
-  return true;
165
-}
166
-
167
-bool enable_cs(uint8_t channel) {
168
-  LogicalChannel* logical_channel = get_logical_channel(channel);
169
-  if(logical_channel == nullptr) return false;
170
-  return set_ssel(logical_channel);
171
-}
172
-
173
-void disable_cs(uint8_t channel) {
174
-  LogicalChannel* logical_channel = get_logical_channel(channel);
175
-  if(logical_channel == nullptr) return;
176
-  if(logical_channel->hw_channel.in_use && !logical_channel->ssel_override) return; //automatic SSel wasn't overridden
177
-
178
-  clear_ssel(logical_channel);
179
-}
180
-
181
-void set_frequency(uint8_t channel, uint32_t frequency) {
182
-  LogicalChannel* logical_channel = get_logical_channel(channel);
183
-  if(logical_channel == nullptr) return;
184
-
185
-  SSP_Cmd(logical_channel->hw_channel.peripheral, DISABLE);
186
-  uint32_t prescale, cr0_div, cmp_clk, ssp_clk;
187
-
188
-  if (logical_channel->hw_channel.peripheral == LPC_SSP0){
189
-    ssp_clk = CLKPWR_GetPCLK (CLKPWR_PCLKSEL_SSP0);
190
-  } else if (logical_channel->hw_channel.peripheral == LPC_SSP1) {
191
-    ssp_clk = CLKPWR_GetPCLK (CLKPWR_PCLKSEL_SSP1);
192
-  } else {
193
-    return;
194
-  }
195
-  //find the closest clock divider / prescaler
196
-  cr0_div = 0;
197
-  cmp_clk = 0xFFFFFFFF;
198
-  prescale = 2;
199
-  while (cmp_clk > frequency) {
200
-    cmp_clk = ssp_clk / ((cr0_div + 1) * prescale);
201
-    if (cmp_clk > frequency) {
202
-      cr0_div++;
203
-      if (cr0_div > 0xFF) {
204
-        cr0_div = 0;
205
-        prescale += 2;
206
-      }
207
-    }
208
-  }
209
-
210
-  logical_channel->hw_channel.peripheral->CR0 &= (~SSP_CR0_SCR(0xFF)) & SSP_CR0_BITMASK;
211
-  logical_channel->hw_channel.peripheral->CR0 |= (SSP_CR0_SCR(cr0_div)) & SSP_CR0_BITMASK;
212
-  logical_channel->CR0 = logical_channel->hw_channel.peripheral->CR0; // preserve for restore
213
-
214
-  logical_channel->hw_channel.peripheral->CPSR = prescale & SSP_CPSR_BITMASK;
215
-  logical_channel->CPSR = logical_channel->hw_channel.peripheral->CPSR; // preserve for restore
216
-
217
-  logical_channel->config.ClockRate = ssp_clk / ((cr0_div + 1) * prescale);
218
-
219
-  SSP_Cmd(logical_channel->hw_channel.peripheral, ENABLE);
220
-}
221
-
222
-void read(uint8_t channel, uint8_t *buffer, uint32_t length) {
223
-  transfer(channel, nullptr, buffer, length);
224
-}
225
-
226
-uint8_t read(uint8_t channel) {
227
-  uint8_t buffer;
228
-  transfer(channel, nullptr, &buffer, 1);
229
-  return buffer;
230
-}
231
-
232
-void write(uint8_t channel, const uint8_t *buffer, uint32_t length) {
233
-  transfer(channel, buffer, nullptr, length);
234
-}
235
-
236
-void write(uint8_t channel, uint8_t value) {
237
-  transfer(channel, &value, nullptr, 1);
238
-}
239
-
240
-void transfer(uint8_t channel, const uint8_t *buffer_write, uint8_t *buffer_read, uint32_t length) {
241
-  LogicalChannel* logical_channel = get_logical_channel(channel);
242
-  if(logical_channel == nullptr) return;
243
-
244
-  if((logical_channel->hw_channel.in_use && !logical_channel->ssel_override) || !logical_channel->hw_channel.initialised) return;
245
-  if(!logical_channel->ssel_override) {
246
-    if(!set_ssel(logical_channel)) return;
247
-  }
248
-
249
-  if(logical_channel != logical_channel->hw_channel.active_channel) {
250
-    restore_frequency(logical_channel);
251
-    logical_channel->hw_channel.active_channel = logical_channel;
252
-  }
253
-
254
-  logical_channel->hw_channel.xfer_config.tx_data = (void *)buffer_write;
255
-  logical_channel->hw_channel.xfer_config.rx_data = (void *)buffer_read;
256
-  logical_channel->hw_channel.xfer_config.length = length;
257
-
258
-  (void)SSP_ReadWrite(logical_channel->hw_channel.peripheral, &logical_channel->hw_channel.xfer_config, SSP_TRANSFER_POLLING); //SSP_TRANSFER_INTERRUPT
259
-
260
-  if(!logical_channel->ssel_override) {
261
-    clear_ssel(logical_channel->hw_channel.active_channel);
262
-  }
263
-}
264
-
265
-uint8_t transfer(uint8_t channel, uint8_t value) {
266
-  uint8_t buffer;
267
-  transfer(channel, &value, &buffer, 1);
268
-  return buffer;
269
-}
270
-
271
-/*
272
- *  Interrupt Handlers
273
- */
274
-extern "C" void ssp_irq_handler(uint8_t hw_channel) {
275
-
276
-  SSP_DATA_SETUP_Type *xf_setup;
277
-  uint32_t tmp;
278
-  uint8_t dataword;
279
-
280
-  // Disable all SSP interrupts
281
-  SSP_IntConfig(hardware_channels[hw_channel].peripheral, SSP_INTCFG_ROR | SSP_INTCFG_RT | SSP_INTCFG_RX | SSP_INTCFG_TX, DISABLE);
282
-
283
-  dataword = (SSP_GetDataSize(hardware_channels[hw_channel].peripheral) > 8) ? 1 : 0;
284
-
285
-  xf_setup = &hardware_channels[hw_channel].xfer_config;
286
-  // save status
287
-  tmp = SSP_GetRawIntStatusReg(hardware_channels[hw_channel].peripheral);
288
-  xf_setup->status = tmp;
289
-
290
-  // Check overrun error
291
-  if (tmp & SSP_RIS_ROR) {
292
-    // Clear interrupt
293
-    SSP_ClearIntPending(hardware_channels[hw_channel].peripheral, SSP_INTCLR_ROR);
294
-    // update status
295
-    xf_setup->status |= SSP_STAT_ERROR;
296
-    // Set Complete Flag
297
-    hardware_channels[hw_channel].xfer_complete = SET;
298
-    if(!hardware_channels[hw_channel].active_channel->ssel_override) clear_ssel(hardware_channels[hw_channel].active_channel);
299
-    return;
300
-  }
301
-
302
-  if ((xf_setup->tx_cnt != xf_setup->length) || (xf_setup->rx_cnt != xf_setup->length)) {
303
-    /* check if RX FIFO contains data */
304
-    while ((SSP_GetStatus(hardware_channels[hw_channel].peripheral, SSP_STAT_RXFIFO_NOTEMPTY)) && (xf_setup->rx_cnt != xf_setup->length)) {
305
-      // Read data from SSP data
306
-      tmp = SSP_ReceiveData(hardware_channels[hw_channel].peripheral);
307
-
308
-      // Store data to destination
309
-      if (xf_setup->rx_data != nullptr) {
310
-        if (dataword == 0) {
311
-          *(uint8_t *) ((uint32_t) xf_setup->rx_data + xf_setup->rx_cnt) = (uint8_t) tmp;
312
-        } else {
313
-          *(uint16_t *) ((uint32_t) xf_setup->rx_data + xf_setup->rx_cnt) = (uint16_t) tmp;
314
-        }
315
-      }
316
-      // Increase counter
317
-      if (dataword == 0) {
318
-        xf_setup->rx_cnt++;
319
-      } else {
320
-        xf_setup->rx_cnt += 2;
321
-      }
322
-    }
323
-
324
-    while ((SSP_GetStatus(hardware_channels[hw_channel].peripheral, SSP_STAT_TXFIFO_NOTFULL)) && (xf_setup->tx_cnt != xf_setup->length)) {
325
-      // Write data to buffer
326
-      if (xf_setup->tx_data == nullptr) {
327
-        if (dataword == 0) {
328
-          SSP_SendData(hardware_channels[hw_channel].peripheral, 0xFF);
329
-          xf_setup->tx_cnt++;
330
-        } else {
331
-          SSP_SendData(hardware_channels[hw_channel].peripheral, 0xFFFF);
332
-          xf_setup->tx_cnt += 2;
333
-        }
334
-      } else {
335
-        if (dataword == 0) {
336
-          SSP_SendData(hardware_channels[hw_channel].peripheral, (*(uint8_t *) ((uint32_t) xf_setup->tx_data + xf_setup->tx_cnt)));
337
-          xf_setup->tx_cnt++;
338
-        } else {
339
-          SSP_SendData(hardware_channels[hw_channel].peripheral, (*(uint16_t *) ((uint32_t) xf_setup->tx_data + xf_setup->tx_cnt)));
340
-          xf_setup->tx_cnt += 2;
341
-        }
342
-      }
343
-
344
-      // Check overrun error
345
-      if (SSP_GetRawIntStatus(hardware_channels[hw_channel].peripheral, SSP_INTSTAT_RAW_ROR)) {
346
-        // update status
347
-        xf_setup->status |= SSP_STAT_ERROR;
348
-        // Set Complete Flag
349
-        hardware_channels[hw_channel].xfer_complete = SET;
350
-        if(!hardware_channels[hw_channel].active_channel->ssel_override) clear_ssel(hardware_channels[hw_channel].active_channel);
351
-        return;
352
-      }
353
-
354
-      // Check for any data available in RX FIFO
355
-      while ((SSP_GetStatus(hardware_channels[hw_channel].peripheral, SSP_STAT_RXFIFO_NOTEMPTY)) && (xf_setup->rx_cnt != xf_setup->length)) {
356
-        // Read data from SSP data
357
-        tmp = SSP_ReceiveData(hardware_channels[hw_channel].peripheral);
358
-
359
-        // Store data to destination
360
-        if (xf_setup->rx_data != nullptr) {
361
-          if (dataword == 0) {
362
-            *(uint8_t *) ((uint32_t) xf_setup->rx_data + xf_setup->rx_cnt) = (uint8_t) tmp;
363
-          } else {
364
-            *(uint16_t *) ((uint32_t) xf_setup->rx_data + xf_setup->rx_cnt) = (uint16_t) tmp;
365
-          }
366
-        }
367
-        // Increase counter
368
-        if (dataword == 0) {
369
-          xf_setup->rx_cnt++;
370
-        } else {
371
-          xf_setup->rx_cnt += 2;
372
-        }
373
-      }
374
-    }
375
-  }
376
-
377
-  // If there more data to sent or receive
378
-  if ((xf_setup->rx_cnt != xf_setup->length) || (xf_setup->tx_cnt != xf_setup->length)) {
379
-    // Enable all interrupt
380
-    SSP_IntConfig(hardware_channels[hw_channel].peripheral, SSP_INTCFG_ROR | SSP_INTCFG_RT | SSP_INTCFG_RX | SSP_INTCFG_TX, ENABLE);
381
-  } else {
382
-    // Save status
383
-    xf_setup->status = SSP_STAT_DONE;
384
-    // Set Complete Flag
385
-    hardware_channels[hw_channel].xfer_complete = SET;
386
-    if(!hardware_channels[hw_channel].active_channel->ssel_override) clear_ssel(hardware_channels[hw_channel].active_channel);
387
-  }
388
-}
389
-
390
-}
391
-}
392
-
393
-extern "C" void SSP0_IRQHandler(void) {
394
-  HAL::SPI::ssp_irq_handler(0);
395
-}
396
-
397
-extern "C" void SSP1_IRQHandler(void) {
398
-  HAL::SPI::ssp_irq_handler(1);
399
-}
400
-
401
-
402
-#endif

+ 1
- 6
Marlin/src/HAL/HAL_LPC1768/spi_pins.h View File

@@ -21,12 +21,7 @@
21 21
 #ifndef SPI_PINS_LPC1768_H
22 22
 #define SPI_PINS_LPC1768_H
23 23
 
24
-//new config options
25
-#define SD_SPI_CHANNEL (HAL::SPI::CHANNEL_2)
26
-#define LCD_SPI_FREQUENCY 4000000
27
-#define LCD_SPI_CHANNEL (HAL::SPI::CHANNEL_1)
28
-
29
-//#define SOFTWARE_SPI
24
+#define SOFTWARE_SPI
30 25
 /** onboard SD card */
31 26
 //#define SCK_PIN           P0_7
32 27
 //#define MISO_PIN          P0_8

+ 0
- 51
Marlin/src/HAL/HAL_TEENSY35_36/spi_impl.cpp View File

@@ -1,51 +0,0 @@
1
-#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
2
-
3
-#include <stdint.h>
4
-
5
-namespace HAL {
6
-namespace SPI {
7
-
8
-bool initialise(uint8_t channel) {
9
-  return false;
10
-}
11
-
12
-bool enable_cs(uint8_t channel) {
13
-  return false;
14
-}
15
-
16
-void disable_cs(uint8_t channel) {
17
-
18
-}
19
-
20
-void set_frequency(uint8_t channel, uint32_t frequency) {
21
-
22
-}
23
-
24
-void read(uint8_t channel, uint8_t *buffer, uint32_t length) {
25
-
26
-}
27
-
28
-uint8_t read(uint8_t channel) {
29
-  return '\0';
30
-}
31
-
32
-void write(uint8_t channel, const uint8_t *buffer, uint32_t length) {
33
-
34
-}
35
-
36
-void write(uint8_t channel, uint8_t value) {
37
-
38
-}
39
-
40
-void transfer(uint8_t channel, const uint8_t *buffer_write, uint8_t *buffer_read, uint32_t length) {
41
-
42
-}
43
-
44
-uint8_t transfer(uint8_t channel, uint8_t value) {
45
-  return '\0';
46
-}
47
-
48
-} // namespace SPI
49
-} // namespace HAL
50
-
51
-#endif //#ifdef ARDUINO_ARCH_AVR

+ 0
- 5
Marlin/src/HAL/HAL_TEENSY35_36/spi_pins.h View File

@@ -20,11 +20,6 @@
20 20
 #ifndef SPI_PINS_H_
21 21
 #define SPI_PINS_H_
22 22
 
23
-//new config options
24
-#define SD_SPI_CHANNEL (HAL::SPI::CHANNEL_0)
25
-#define LCD_SPI_FREQUENCY 4000000
26
-#define LCD_SPI_CHANNEL (HAL::SPI::CHANNEL_1)
27
-
28 23
 #define SCK_PIN		13
29 24
 #define MISO_PIN	12
30 25
 #define MOSI_PIN	11

+ 0
- 46
Marlin/src/HAL/spi_api.h View File

@@ -1,46 +0,0 @@
1
-#ifndef _SPI_API_H_
2
-#define _SPI_API_H_
3
-
4
-#include <stdint.h>
5
-#include "HAL_spi_pins.h"
6
-
7
-namespace HAL {
8
-namespace SPI {
9
-
10
-enum SPI_CHANNELS {
11
-  CHANNEL_0 = 0,
12
-  CHANNEL_1,
13
-  CHANNEL_2,
14
-  CHANNEL_3,
15
-  CHANNEL_4,
16
-  CHANNEL_5
17
-};
18
-
19
-/*
20
- * Initialise the hardware layer (pins and peripheral)
21
- */
22
-bool initialise(uint8_t channel);
23
-
24
-/*
25
- * Allow override of automatic Chip Select
26
- */
27
-bool enable_cs(uint8_t channel);
28
-void disable_cs(uint8_t channel);
29
-
30
-
31
-void set_frequency(uint8_t channel, uint32_t frequency);
32
-
33
-void read(uint8_t channel, uint8_t *buffer, uint32_t length);
34
-uint8_t read(uint8_t channel);
35
-
36
-void write(uint8_t channel, const uint8_t *buffer, uint32_t length);
37
-void write(uint8_t channel, uint8_t value);
38
-
39
-void transfer(uint8_t channel, const uint8_t *buffer_write, uint8_t *buffer_read, uint32_t length);
40
-uint8_t transfer(uint8_t channel, uint8_t value);
41
-
42
-}
43
-}
44
-
45
-
46
-#endif /* _SPI_API_H_ */

+ 10
- 11
Marlin/ultralcd_st7920_u8glib_rrd.h View File

@@ -105,22 +105,21 @@ static void ST7920_SWSPI_SND_8BIT(uint8_t val) {
105 105
   #define U8G_DELAY() u8g_10MicroDelay()
106 106
 #endif
107 107
 
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
-
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(); }
117 114
 
118 115
 uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
119 116
   uint8_t i, y;
120 117
   switch (msg) {
121 118
     case U8G_DEV_MSG_INIT: {
122
-      HAL::SPI::initialise(LCD_SPI_CHANNEL);
123
-      HAL::SPI::set_frequency(LCD_SPI_CHANNEL, LCD_SPI_FREQUENCY);
119
+      OUT_WRITE(ST7920_CS_PIN, LOW);
120
+      OUT_WRITE(ST7920_DAT_PIN, LOW);
121
+      OUT_WRITE(ST7920_CLK_PIN, HIGH);
122
+
124 123
       ST7920_CS();
125 124
       u8g_Delay(120);                 //initial delay for boot up
126 125
       ST7920_SET_CMD();

Loading…
Cancel
Save