-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathattiny817_drv.h
75 lines (60 loc) · 1.35 KB
/
attiny817_drv.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* attiny817_drv.h
*
* Created: 24-Apr-18 23:05:44
* Author: Jürgen Laks
*/
#ifndef ATTINY817_DRV_H_
#define ATTINY817_DRV_H_
#include <inttypes.h>
#include <avr/interrupt.h>
#include <stdint.h>
// Define system CPU frequency
#define F_CPU (20000000UL)
#define _BV(bit) (1 << (bit))
#define noInterrupts() cli()
#define enableInterrupts() sei()
#include "drivers/attiny817_gpio.h"
#include "drivers/attiny817_serial.h"
#include "drivers/attiny817_misc.h"
#include "drivers/attiny817_SPI.h"
inline void hal_init(){
// Clock setup
CPU_CCP = 0xD8; // Disable write-protect from clock registers
CLKCTRL.MCLKCTRLB = 0; // disable clkdiv to get 20MHz clock speed
// RTC setup
RTC.CTRLA = RTC_PRESCALER_DIV1_gc | RTC_RTCEN_bm; // Enable RTC and set the clock prescaler
RTC.INTCTRL = RTC_OVF_bm;
RTC.CLKSEL = RTC_CLKSEL_INT32K_gc; // Set clock to 32.768kHz from XOSC32K
sei();
}
/** ADC */
//uint16_t analogRead(uint8_t channel);
/** PWM */
//void analogWrite(uint8_t pin, uint8_t value);
/*
To be implemented: I2C (Wire)
begin()
requestFrom()
beginTransmission()
endTransmission()
write()
available()
read()
SetClock()
onReceive()
onRequest()
*/
/*
To be implemented: SPI (Wire)
begin()
end()
beginTransaction()
endTransaction()
setBitOrder()
setClockDivider()
setDataMode()
transfer()
usingInterrupt()
*/
#endif /* ATTINY817_DRV_H_ */