-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptoTWIM.h
More file actions
144 lines (129 loc) · 4.8 KB
/
Copy pathOptoTWIM.h
File metadata and controls
144 lines (129 loc) · 4.8 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* OptoTWIM.h
*
*
* Author: Caroline
*
* Description: Header file for the TWI for interfacing with the
* MCP4728 (12-bit DAC)
*/
#ifndef OPTOTWIM_H_
#define OPTOTWIM_H_
#include <avr32/io.h>
#include <stdint.h>
#include "avr32\twim_101.h"
/************************************************************************/
/* NOTE:
/* To use TWIM interface, you'll need to add these lines back into
/* main.c:
/* volatile avr32_twim_t *twi = &AVR32_TWIM1;
/* enable_gpio_pin(AVR32_PIN_PA17);
/* enable_gpio_pin(AVR32_PIN_PA05);
/* assign_gpio_module(AVR32_TWIMS1_TWCK_0_0_PIN, AVR32_TWIMS1_TWCK_0_0_FUNCTION);
/* assign_gpio_module(AVR32_TWIMS1_TWD_0_PIN, AVR32_TWIMS1_TWD_0_FUNCTION);
/************************************************************************/
/************************************************************************/
/* Enable and configure the TWI
/*
/* Parameters:
/* avr32_twim_t *twim - base address of TWIM
/* uint32_t twim_speed - clock speed for TWIM
/* uint32_t twim_addr - slave address to write to
/* uint32_t pb_freq - peripheral bus speed
/*
/* Returns:
/* 1 for success; 0 otherwise
/************************************************************************/
uint8_t init_twim(volatile avr32_twim_t *twim, uint32_t twim_speed, uint32_t twim_addr, uint32_t pb_freq);
/************************************************************************/
/* Enable and configure the TWI
/*
/* Parameters:
/* avr32_twim_t *twim - base address of TWIM
/* uint32_t twim_speed - clock speed for TWIM
/* uint32_t pb_f - peripheral bus speed
/*
/* Returns:
/* 1 for success; 0 otherwise
/************************************************************************/
void set_twim_speed(volatile avr32_twim_t *twim, uint32_t twim_speed, uint32_t pb_f);
/************************************************************************/
/* Enable and configure the TWI
/*
/* Parameters:
/* avr32_twim_t *twim - base address of TWIM
/* uint32_t addr - slave address to write to
/*
/* Returns:
/* 1 for success; 0 otherwise
/************************************************************************/
uint8_t twim_ping_chip(volatile avr32_twim_t *twim, uint32_t addr);
/************************************************************************/
/* TWI Write
/*
/* Parameters:
/* avr32_twim_t *twim - base address of TWIM
/* uint16_t buff_data - data to transfer
/* uint32_t twim_addr - slave address to write to
/* uint8_t dac_cmd - command for DAC communication
/*
/* SUPPORTED COMMANDS for MCP4728:
/* 0 - Ping DAC (verify DAC is connected to microcontroller)
/* 1 - Wakeup DAC
/* 2 - Software Update (updates all channels)
/* 3 - Reset DAC
/* 4 - Write to DAC
/*
/* Returns:
/* 1 for success; 0 otherwise
/************************************************************************/
uint8_t twim_write(volatile avr32_twim_t *twim, uint16_t buff_data, uint32_t twim_addr, uint8_t dac_cmd);
/************************************************************************/
/* MCP4728 Specific Commands
/************************************************************************/
/************************************************************************/
/* Remove DAC from idle state
/*
/* Parameters:
/* avr32_twim_t *twim - base address of TWIM
/* uint32_t twim_addr - slave address to write to
/*
/* Returns:
/* 1 for success; 0 otherwise
/************************************************************************/
uint8_t dac_wakeup_cmd(volatile avr32_twim_t *twim, uint32_t twim_addr);
/************************************************************************/
/* Update all DAC outputs with current content of DAC memory
/*
/* Parameters:
/* avr32_twim_t *twim - base address of TWIM
/* uint32_t twim_addr - slave address to write to
/*
/* Returns:
/* 1 for success; 0 otherwise
/************************************************************************/
uint8_t dac_software_update(volatile avr32_twim_t *twim, uint32_t twim_addr);
/************************************************************************/
/* Reset current DAC configuration
/*
/* Parameters:
/* avr32_twim_t *twim - base address of TWIM
/* uint32_t twim_addr - slave address to write to
/*
/* Returns:
/* 1 for success; 0 otherwise
/************************************************************************/
uint8_t dac_reset_cmd(volatile avr32_twim_t *twim, uint32_t twim_addr);
/************************************************************************/
/* Write to DAC memory
/*
/* Parameters:
/* avr32_twim_t *twim - base address of TWIM
/* uint32_t twim_addr - slave address to write to
/* uint16_t twim_buffer - data to write to DAC memory
/*
/* Returns:
/* 1 for success; 0 otherwise
/************************************************************************/
uint8_t dac_write_cmd(volatile avr32_twim_t *twim, uint32_t twim_addr, uint16_t twim_buffer);
#endif /* OPTOTWIM_H_ */