Prusa MINI Firmware overview
softspi.h File Reference
#include "../HAL/shared/Marduino.h"
#include <avr/io.h>
#include <util/atomic.h>

Go to the source code of this file.

Classes

class  pin_map_t
 struct for mapping digital pins More...
 
class  DigitalPin< PinNumber >
 Fast digital port I/O. More...
 
class  SoftSPI< MisoPin, MosiPin, SckPin, Mode >
 Fast software SPI. More...
 

Macros

#define FORCE_INLINE   inline __attribute__((always_inline))
 
#define nop   __asm__ volatile ("nop")
 

Functions

void badPinNumber () __attribute__((error("Pin number is too large or not a const ant")))
 
static FORCE_INLINE void badPinCheck (const uint8_t pin)
 
static FORCE_INLINE void fastBitWriteSafe (volatile uint8_t *address, uint8_t bit, bool level)
 
static FORCE_INLINE bool fastDigitalRead (uint8_t pin)
 
static FORCE_INLINE void fastDigitalToggle (uint8_t pin)
 
static FORCE_INLINE void fastDigitalWrite (uint8_t pin, bool level)
 
static FORCE_INLINE void fastPinMode (uint8_t pin, bool mode)
 
static FORCE_INLINE void fastPinConfig (uint8_t pin, bool mode, bool level)
 

Variables

static constexpr uint8_t digitalPinCount = sizeof(pinMap) / sizeof(pin_map_t)
 
const bool MISO_MODE = false
 
const bool MISO_LEVEL = false
 
const bool MOSI_MODE = true
 
const bool SCK_MODE = true
 

Macro Definition Documentation

◆ FORCE_INLINE

#define FORCE_INLINE   inline __attribute__((always_inline))

Marlin 3D Printer Firmware Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]

Based on Sprinter and grbl. Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

◆ nop

#define nop   __asm__ volatile ("nop")

Function Documentation

◆ badPinNumber()

void badPinNumber ( ) const

generate bad pin number error

Here is the caller graph for this function:

◆ badPinCheck()

static FORCE_INLINE void badPinCheck ( const uint8_t  pin)
static

Check for valid pin number

Parameters
[in]pinNumber of pin to be checked.
485  {
486  if (!__builtin_constant_p(pin) || pin >= digitalPinCount) badPinNumber();
487  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fastBitWriteSafe()

static FORCE_INLINE void fastBitWriteSafe ( volatile uint8_t address,
uint8_t  bit,
bool  level 
)
static

Fast write helper

Parameters
[in]addressI/O register address
[in]bitbit number to write
[in]levelvalue for bit
495  {
496  uint8_t oldSREG;
497  if (address > (uint8_t*)0x5F) { oldSREG = SREG; cli(); }
498  if (level) SBI(*address, bit); else CBI(*address, bit);
499  if (address > (uint8_t*)0x5F) SREG = oldSREG;
500  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fastDigitalRead()

static FORCE_INLINE bool fastDigitalRead ( uint8_t  pin)
static

Read pin value

Parameters
[in]pinArduino pin number
Returns
value read
507  {
508  badPinCheck(pin);
509  return (*pinMap[pin].pin >> pinMap[pin].bit) & 1;
510  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fastDigitalToggle()

static FORCE_INLINE void fastDigitalToggle ( uint8_t  pin)
static

Toggle a pin

Parameters
[in]pinArduino pin number

If the pin is in output mode toggle the pin level. If the pin is in input mode toggle the state of the 20K pullup.

519  {
520  badPinCheck(pin);
521  if (pinMap[pin].pin > (uint8_t*)0x5F)
522  *pinMap[pin].pin = _BV(pinMap[pin].bit); // Must write bit to high address port
523  else
524  SBI(*pinMap[pin].pin, pinMap[pin].bit); // Compiles to sbi and PIN register will not be read
525  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fastDigitalWrite()

static FORCE_INLINE void fastDigitalWrite ( uint8_t  pin,
bool  level 
)
static

Set pin value

Parameters
[in]pinArduino pin number
[in]levelvalue to write
532  {
533  badPinCheck(pin);
534  fastBitWriteSafe(pinMap[pin].port, pinMap[pin].bit, level);
535  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fastPinMode()

static FORCE_INLINE void fastPinMode ( uint8_t  pin,
bool  mode 
)
static

Set pin mode

Parameters
[in]pinArduino pin number
[in]modeif true set output mode else input mode

fastPinMode does not enable or disable the 20K pullup for input mode.

544  {
545  badPinCheck(pin);
546  fastBitWriteSafe(pinMap[pin].ddr, pinMap[pin].bit, mode);
547  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fastPinConfig()

static FORCE_INLINE void fastPinConfig ( uint8_t  pin,
bool  mode,
bool  level 
)
static

Set pin configuration

Parameters
[in]pinArduino pin number
[in]modeIf true set output mode else input mode
[in]levelIf mode is output, set level high/low. If mode is input, enable or disable the pin's 20K pullup.
558  {
559  fastPinMode(pin, mode);
560  fastDigitalWrite(pin, level);
561 }
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ digitalPinCount

constexpr uint8_t digitalPinCount = sizeof(pinMap) / sizeof(pin_map_t)
staticconstexpr

count of pins

◆ MISO_MODE

const bool MISO_MODE = false

◆ MISO_LEVEL

const bool MISO_LEVEL = false

◆ MOSI_MODE

const bool MOSI_MODE = true

◆ SCK_MODE

const bool SCK_MODE = true
fastPinMode
static FORCE_INLINE void fastPinMode(uint8_t pin, bool mode)
Definition: softspi.h:544
badPinNumber
void badPinNumber() __attribute__((error("Pin number is too large or not a const ant")))
fastDigitalWrite
static FORCE_INLINE void fastDigitalWrite(uint8_t pin, bool level)
Definition: softspi.h:532
fastBitWriteSafe
static FORCE_INLINE void fastBitWriteSafe(volatile uint8_t *address, uint8_t bit, bool level)
Definition: softspi.h:495
cli
void cli()
uint8_t
const uint8_t[]
Definition: 404_html.c:3
address
UsbDeviceAddress address
Definition: address.h:202
_BV
#define _BV(bit)
Definition: wiring_constants.h:99
CBI
#define CBI(A, B)
Definition: macros.h:89
digitalPinCount
static constexpr uint8_t digitalPinCount
Definition: softspi.h:475
SBI
#define SBI(A, B)
Definition: macros.h:85
mode
png_structrp int mode
Definition: png.h:1139
badPinCheck
static FORCE_INLINE void badPinCheck(const uint8_t pin)
Definition: softspi.h:485
bit
#define bit(b)
Definition: wiring_constants.h:96