Revision 888
Added the header files for spi, encoders, and eeprom to the trunk library.
Recompiled library :P
trunk/code/lib/include/libdragonfly/spi.h | ||
---|---|---|
1 |
/** |
|
2 |
* @file spi.h |
|
3 |
* @brief Definitions for SPI |
|
4 |
* @author Colony Project, CMU Robotics Club |
|
5 |
**/ |
|
6 |
|
|
7 |
/** |
|
8 |
* @addtogroup spi |
|
9 |
* @{ |
|
10 |
**/ |
|
11 |
|
|
12 |
#ifndef __SPI_H__ |
|
13 |
#define __SPI_H__ |
|
14 |
|
|
15 |
#define DOUBLE_SCK 1 |
|
16 |
#define SPR0_BIT 1 |
|
17 |
|
|
18 |
#define MASTER 1 |
|
19 |
#define SLAVE 0 |
|
20 |
|
|
21 |
#define MOSI _BV(PB2) |
|
22 |
#define MISO _BV(PB3) |
|
23 |
#define SS _BV(PB0) |
|
24 |
#define SCLK _BV(PB1) |
|
25 |
|
|
26 |
typedef void (*spi_fun_recv_t)(char); |
|
27 |
typedef void (*spi_fun_recv_complete_t)(void); |
|
28 |
|
|
29 |
/** |
|
30 |
* @brief Initialize SPI |
|
31 |
* |
|
32 |
* @param spi_fun_recv_t The function that handles SPI data, byte for byte. |
|
33 |
* @param spi_fun_recv_complete_t Called on a completed transmission - typically for cleaning up. |
|
34 |
*/ |
|
35 |
void spi_init (spi_fun_recv_t, spi_fun_recv_complete_t); |
|
36 |
|
|
37 |
/** |
|
38 |
* @brief Initialize SPI transfer. |
|
39 |
* |
|
40 |
* @param char The number of bytes to transfer. |
|
41 |
*/ |
|
42 |
void spi_transfer (char); |
|
43 |
|
|
44 |
/**@}**/ //end group |
|
45 |
|
|
46 |
#endif |
trunk/code/lib/include/libdragonfly/encoders.h | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
* @file encoders.h |
|
4 |
* @brief Contains functions for reading encoder values. |
|
5 |
* |
|
6 |
* Contains high and low level functions for reading encoders |
|
7 |
* including reading out total distance covered, and |
|
8 |
* eventually velocity. |
|
9 |
* |
|
10 |
* @author Colony Project, CMU Robotics Club |
|
11 |
*/ |
|
12 |
|
|
13 |
/** |
|
14 |
* @addtogroup encoders |
|
15 |
* @{ |
|
16 |
**/ |
|
17 |
|
|
18 |
#ifndef __ENCODERS_H__ |
|
19 |
#define __ENCODERS_H__ |
|
20 |
|
|
21 |
|
|
22 |
#ifndef LEFT |
|
23 |
#define LEFT 0 |
|
24 |
#endif |
|
25 |
#ifndef RIGHT |
|
26 |
#define RIGHT 1 |
|
27 |
#endif |
|
28 |
|
|
29 |
/** @brief Magnet misaligned - likely distance from encoder problem. **/ |
|
30 |
#define ENCODER_MAGNET_FAILURE 1025 |
|
31 |
/** @brief Encoder misaligned - likely on XY plane. **/ |
|
32 |
#define ENCODER_MISALIGNED 1027 |
|
33 |
/** @brief Not enough time has passed - encoders not initialized in hardware. **/ |
|
34 |
#define ENCODER_DATA_NOT_READY 1026 |
|
35 |
|
|
36 |
//delay_ms argument after a full read is complete |
|
37 |
#define ENCODER_DELAY 20 |
|
38 |
|
|
39 |
#define MIN_V (-100) |
|
40 |
#define MAX_V 100 |
|
41 |
|
|
42 |
//Data invalid flags (hardware failure): |
|
43 |
#define OCF _BV(4) |
|
44 |
#define COF _BV(3) |
|
45 |
|
|
46 |
//Data invalid alarm (May be invalid): |
|
47 |
#define LIN _BV(2) |
|
48 |
|
|
49 |
#define MagINCn _BV(1) |
|
50 |
#define MagDECn _BV(0) |
|
51 |
|
|
52 |
#define BUFFER_SIZE 23 |
|
53 |
|
|
54 |
/** @brief Initialize encoders. **/ |
|
55 |
void encoders_init(void); |
|
56 |
/** @brief Read instantaneous encoder value. **/ |
|
57 |
int encoder_read(char encoder); |
|
58 |
|
|
59 |
/** @brief Get total distance traveled. **/ |
|
60 |
int encoder_get_dx(char encoder); |
|
61 |
/** @brief Reset distance counter. **/ |
|
62 |
void encoder_rst_dx(char encoder); |
|
63 |
/** @brief Get time count: The number of encoder reads that have occurred. **/ |
|
64 |
int encoder_get_tc(void); |
|
65 |
/** @brief Reset the time count. **/ |
|
66 |
void encoder_rst_tc(void); |
|
67 |
|
|
68 |
/** @brief Waits for the next n encoder reading, then returns. **/ |
|
69 |
void encoder_wait( int nReadings ); |
|
70 |
|
|
71 |
/**@}**/ //end group |
|
72 |
|
|
73 |
#endif |
trunk/code/lib/include/libdragonfly/eeprom.h | ||
---|---|---|
1 |
/** |
|
2 |
* @file eeprom.h |
|
3 |
* @brief handles eeprom storage for persistent data |
|
4 |
* |
|
5 |
* Contains functions and definitions for reading and writing to eeprom |
|
6 |
* |
|
7 |
* @author Colony Project, Brad Neuman |
|
8 |
*/ |
|
9 |
|
|
10 |
#ifndef _EEPROM_H_ |
|
11 |
#define _EEPROM_H_ |
|
12 |
|
|
13 |
#define EEPROM_ROBOT_ID_ADDR 0x0b |
|
14 |
|
|
15 |
/** @brief store a byte to eeproem |
|
16 |
* @return 0 if success, nonzero on failure |
|
17 |
*/ |
|
18 |
int eeprom_put_byte(unsigned int addr, unsigned char byte); |
|
19 |
|
|
20 |
/** @brief reads a byte from eeprom |
|
21 |
* |
|
22 |
* Pass it thge address and a pointer to a byte where the byte at the |
|
23 |
* address will be stored |
|
24 |
* |
|
25 |
* @return 0 if successful (byte is set to the eeprom value at addr), |
|
26 |
* nonzero if there was a problem |
|
27 |
*/ |
|
28 |
int eeprom_get_byte(unsigned int addr, unsigned char *byte); |
|
29 |
|
|
30 |
/** @brief get stored robot ID |
|
31 |
* |
|
32 |
* returnes the value of eerpom at EEPROM_ROBOT_ID_ADDR |
|
33 |
* |
|
34 |
* @return the robot id, if it is stored. If it returns 0xff it is probably invalid |
|
35 |
*/ |
|
36 |
unsigned char get_robotid(void); |
|
37 |
|
|
38 |
#endif |
|
39 |
|
Also available in: Unified diff