Changeset a6ae6ac in avrstuff for EPRoxygen/device.h
- Timestamp:
- Jul 9, 2012, 11:05:43 PM (12 years ago)
- Branches:
- main
- Children:
- 16cf6ff
- Parents:
- 34c57e8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EPRoxygen/device.h
r34c57e8 ra6ae6ac 7 7 #include <stdio.h> 8 8 #include <stdint.h> 9 #include <unistd.h> 9 10 10 11 // FreeBSD … … 42 43 protected: 43 44 typedef enum { 44 NONE = 0b0 101, /* Nothing selected */45 NYBLE = 0b0 010, /* Read low nyble */45 NONE = 0b0011, /* Nothing selected */ 46 NYBLE = 0b0100, /* Read low nyble */ 46 47 /* When 0, status reg shows D0.3 47 48 * When 1, status reg shows D4.7 48 49 */ 49 CTRL = 0b0 011, /* Control reg. */50 CTRL = 0b0101, /* Control reg. */ 50 51 /* b0: A16 51 * b1: /A17 52 * b1: /A17 (A17 is reversed !) 52 53 * b2: WE 53 54 * b3: A18 … … 71 72 * b7: VCC enable (1 = power ON) 72 73 */ 73 ADR0 = 0b1 011, /* Low address byte A0.7 */74 ADR0 = 0b1101, /* Low address byte A0.7 */ 74 75 DATA = 0b1110, /* Data byte */ 75 76 ADR1 = 0b1111, /* High address byte A8.15 */ 77 /* A13 is reversed ! (also used as VCC pin in smaller packages) 78 */ 76 79 } Register; 80 81 static const uint8_t A13 = 1 << 5; 77 82 78 83 typedef enum { … … 102 107 static inline void write(const Register reg, const uint8_t val) 103 108 { 104 // The register latches the data only when another register gets 105 // selected. If this is a problem, select the NONE reg after 106 // writing ! 109 // To avoid glitches, first set the bits that select the register, 110 // then enable the output. And disable the output when we are done 111 // while not touching the selected reg. This is the only way to 112 // avoid glitches (another reg may be selected long enough for 113 // losing some bits) 114 outb(port, val); 115 usleep(1000); 116 outb(port + 2, reg ^ 4); 117 usleep(1000); 107 118 outb(port + 2, reg); 108 outb(port, val); 119 usleep(1000); 120 outb(port + 2, reg ^ 4); 121 usleep(1000); 109 122 } 110 123 111 124 static inline uint8_t read() 112 125 { 113 uint8_t byte = (inb(port + 1) ^ 0x80) & 0xF0; 126 outb(port+2, NYBLE ^ 4); 127 usleep(1000); 128 uint8_t byte = inb(port + 1) & 0xF0; 114 129 115 130 outb(port+2, NYBLE); 116 byte |= (inb(port + 1) ^ 0x80) >> 4; 117 return byte; 131 usleep(1000); 132 byte |= inb(port + 1) >> 4; 133 printf("R %X", byte ^ 0x88); 134 getchar(); 135 outb(port+2, NYBLE ^ 4); 136 usleep(1000); 137 return byte ^ 0x88; 118 138 } 119 139 140 static int port; 120 141 private: 121 static int port;122 142 }; 123 143
Note:
See TracChangeset
for help on using the changeset viewer.