File tree 3 files changed +25
-19
lines changed
3 files changed +25
-19
lines changed Original file line number Diff line number Diff line change @@ -392,30 +392,34 @@ void uart_ignore_char(char c) {
392
392
393
393
void uart0_write_char (char c) {
394
394
if (&Serial != NULL && Serial.isTxEnabled ()) {
395
- if (c == ' \n ' ) {
396
- Serial.write (' \r ' );
397
- }
398
- Serial.write (c);
399
- } else {
400
- if (c == ' \n ' ) {
401
- USF (0 ) = ' \r ' ;
395
+ if (Serial.availableForWrite () > 0 ) {
396
+ if (c == ' \n ' ) {
397
+ Serial.write (' \r ' );
398
+ }
399
+ Serial.write (c);
400
+ return ;
402
401
}
403
- USF (0 ) = c;
404
402
}
403
+ if (c == ' \n ' ) {
404
+ USF (0 ) = ' \r ' ;
405
+ }
406
+ USF (0 ) = c;
405
407
}
406
408
407
409
void uart1_write_char (char c) {
408
410
if (&Serial1 != NULL && Serial1.isTxEnabled ()) {
409
- if (c == ' \n ' ) {
410
- Serial1.write (' \r ' );
411
- }
412
- Serial1.write (c);
413
- } else {
414
- if (c == ' \n ' ) {
415
- USF (1 ) = ' \r ' ;
411
+ if (Serial1.availableForWrite () > 0 ) {
412
+ if (c == ' \n ' ) {
413
+ Serial1.write (' \r ' );
414
+ }
415
+ Serial1.write (c);
416
+ return ;
416
417
}
417
- USF (1 ) = c;
418
418
}
419
+ if (c == ' \n ' ) {
420
+ USF (1 ) = ' \r ' ;
421
+ }
422
+ USF (1 ) = c;
419
423
}
420
424
421
425
static int s_uart_debug_nr = UART0;
Original file line number Diff line number Diff line change @@ -121,14 +121,14 @@ void SPIClass::setBitOrder(uint8_t bitOrder) {
121
121
* @return
122
122
*/
123
123
static uint32_t ClkRegToFreq (spiClk_t * reg) {
124
- return (F_CPU / ((reg->regPre + 1 ) * (reg->regN + 1 )));
124
+ return (SPI_MAX_SPEED / ((reg->regPre + 1 ) * (reg->regN + 1 )));
125
125
}
126
126
127
127
void SPIClass::setFrequency (uint32_t freq) {
128
128
static uint32_t lastSetFrequency = 0 ;
129
129
static uint32_t lastSetRegister = 0 ;
130
130
131
- if (freq >= F_CPU ) {
131
+ if (freq >= SPI_MAX_SPEED ) {
132
132
setClockDivider (0x80000000 );
133
133
return ;
134
134
}
@@ -164,7 +164,7 @@ void SPIClass::setFrequency(uint32_t freq) {
164
164
reg.regN = calN;
165
165
166
166
while (calPreVari++ <= 1 ) { // test different variants for Pre (we calculate in int so we miss the decimals, testing is the easyest and fastest way)
167
- calPre = (((F_CPU / (reg.regN + 1 )) / freq) - 1 ) + calPreVari;
167
+ calPre = (((SPI_MAX_SPEED / (reg.regN + 1 )) / freq) - 1 ) + calPreVari;
168
168
if (calPre > 0x1FFF ) {
169
169
reg.regPre = 0x1FFF ; // 8191
170
170
} else if (calPre <= 0 ) {
Original file line number Diff line number Diff line change 45
45
#define SPI_CLOCK_DIV64 0x04fc1001 // 250 KHz
46
46
#endif
47
47
48
+ #define SPI_MAX_SPEED (80000000L )
49
+
48
50
const uint8_t SPI_MODE0 = 0x00 ; // /< CPOL: 0 CPHA: 0
49
51
const uint8_t SPI_MODE1 = 0x01 ; // /< CPOL: 0 CPHA: 1
50
52
const uint8_t SPI_MODE2 = 0x10 ; // /< CPOL: 1 CPHA: 0
You can’t perform that action at this time.
0 commit comments