ATtiny85 Template Code
Code snippets for the ATtiny85
 All Files Functions Variables Typedefs Enumerations Enumerator Macros
iohelp.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------*
2 * IO convenience functions
3 *---------------------------------------------------------------------------*
4 * 16-Apr-2014 ShaneG
5 *
6 * These functions provide simple ways to deal with common IO functions.
7 *--------------------------------------------------------------------------*/
8 #ifndef __IOHELP_H
9 #define __IOHELP_H
10 
11 //--- Required definitions
12 #include <stdint.h>
13 #include <stdbool.h>
14 #include <avr/io.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 //---------------------------------------------------------------------------
21 // Digital helper functions
22 //---------------------------------------------------------------------------
23 
30 #define pinHigh(pin) \
31  PORTB |= (1 << pin)
32 
39 #define pinLow(pin) \
40  PORTB &= ~(1 << pin)
41 
49 void pinSet(uint8_t pin, bool value);
50 
55 #define pinGet(pin) \
56  (PINB & (1 << pin))
57 
58 //---------------------------------------------------------------------------
59 // Analog helper functions
60 //---------------------------------------------------------------------------
61 
64 typedef enum _ANALOG {
65  ADC0 = 0x00,
66  ADC1,
67  ADC2,
68  ADC3,
69  ADC4 = 0x0F
70  } ANALOG;
71 
81 void adcInit(ANALOG adc);
82 
94 uint16_t adcRead(ANALOG adc, uint8_t skip, uint8_t average);
95 
96 //---------------------------------------------------------------------------
97 // Hardware PWM helpers
98 //---------------------------------------------------------------------------
99 
104 typedef enum _PWM {
105  PWM0 = 0,
106  PWM1 = 1,
107  } PWM;
108 
114 void pwmInit();
115 
124 void pwmOut(PWM pwm, uint8_t value);
125 
126 //---------------------------------------------------------------------------
127 // Software PWM implementation
128 //---------------------------------------------------------------------------
129 
134 typedef enum _SPWM {
135  SPWM0 = 0,
136  SPWM1 = 1,
137  SPWM2 = 2,
138  SPWM3 = 3,
139  } SPWM;
140 
146 void spwmInit();
147 
156 void spwmOut(SPWM pwm, uint8_t value);
157 
166 uint8_t spwmValue(SPWM pwm);
167 
168 //---------------------------------------------------------------------------
169 // Software SPI
170 //---------------------------------------------------------------------------
171 
182 void sspiInit(uint8_t sck, uint8_t mosi, uint8_t miso);
183 
191 void sspiOutMSB(uint8_t sck, uint8_t mosi, uint16_t data, uint8_t bits);
192 
201 uint16_t sspiInMSB(uint8_t sck, uint8_t miso, uint8_t bits);
202 
213 uint16_t sspiInOutMSB(uint8_t sck, uint8_t mosi, uint8_t miso, uint16_t data, uint8_t bits);
214 
222 void sspiOutLSB(uint8_t sck, uint8_t mosi, uint16_t data, uint8_t bits);
223 
232 uint16_t sspiInLSB(uint8_t sck, uint8_t miso, uint8_t bits);
233 
244 uint16_t sspiInOutLSB(uint8_t sck, uint8_t mosi, uint8_t miso, uint16_t data, uint8_t bits);
245 
246 #ifdef __cplusplus
247 }
248 #endif
249 
250 #endif /* __IOHELP_H */
_ANALOG
Definition: iohelp.h:64
PWM output 1 (PB1)
Definition: iohelp.h:106
void sspiOutLSB(uint8_t sck, uint8_t mosi, uint16_t data, uint8_t bits)
Definition: softspi.c:129
uint16_t adcRead(ANALOG adc, uint8_t skip, uint8_t average)
Definition: analog.c:61
_PWM
Definition: iohelp.h:104
uint16_t sspiInOutMSB(uint8_t sck, uint8_t mosi, uint8_t miso, uint16_t data, uint8_t bits)
Definition: softspi.c:95
_SPWM
Definition: iohelp.h:134
ADC1, PB2.
Definition: iohelp.h:66
uint16_t sspiInMSB(uint8_t sck, uint8_t miso, uint8_t bits)
Definition: softspi.c:68
void spwmInit()
Definition: systicks.c:107
uint8_t spwmValue(SPWM pwm)
Definition: systicks.c:153
enum _PWM PWM
void adcInit(ANALOG adc)
Definition: analog.c:20
ADC2, PB4.
Definition: iohelp.h:67
uint16_t sspiInOutLSB(uint8_t sck, uint8_t mosi, uint8_t miso, uint16_t data, uint8_t bits)
Definition: softspi.c:184
void pinSet(uint8_t pin, bool value)
void spwmOut(SPWM pwm, uint8_t value)
Definition: systicks.c:140
Software PWM output 0 (defined by SPWM_PIN0)
Definition: iohelp.h:135
Software PWM output 3 (defined by SPWM_PIN3)
Definition: iohelp.h:138
void pwmOut(PWM pwm, uint8_t value)
Definition: pwm.c:30
void sspiInit(uint8_t sck, uint8_t mosi, uint8_t miso)
Definition: softspi.c:22
Software PWM output 2 (defined by SPWM_PIN2)
Definition: iohelp.h:137
void pwmInit()
Definition: pwm.c:17
uint16_t sspiInLSB(uint8_t sck, uint8_t miso, uint8_t bits)
Definition: softspi.c:156
void sspiOutMSB(uint8_t sck, uint8_t mosi, uint16_t data, uint8_t bits)
Definition: softspi.c:40
ADC3, PB3.
Definition: iohelp.h:68
ADC4 - internal temperature sensor.
Definition: iohelp.h:69
Software PWM output 1 (defined by SPWM_PIN1)
Definition: iohelp.h:136
enum _SPWM SPWM
ADC0, PB5.
Definition: iohelp.h:65
PWM output 0 (PB0)
Definition: iohelp.h:105
enum _ANALOG ANALOG