modified docs a little about row/col assignments
and linked-list stuff still in progresspartial-rewrite
parent
018b763423
commit
a31b0fa507
|
@ -12,7 +12,7 @@
|
||||||
inkscape:version="0.48.2 r9819"
|
inkscape:version="0.48.2 r9819"
|
||||||
version="1.1"
|
version="1.1"
|
||||||
id="svg2"
|
id="svg2"
|
||||||
height="398.98083"
|
height="416.48083"
|
||||||
width="950.8382"
|
width="950.8382"
|
||||||
sodipodi:docname="circuit-diagram.svg"
|
sodipodi:docname="circuit-diagram.svg"
|
||||||
inkscape:export-filename="/home/ben/Desktop/programs/20120227--ergodox-firmware--for-the-ergodox-keyboard/src/test - circuit diagram/inkscape/_circuit-diagram.png"
|
inkscape:export-filename="/home/ben/Desktop/programs/20120227--ergodox-firmware--for-the-ergodox-keyboard/src/test - circuit diagram/inkscape/_circuit-diagram.png"
|
||||||
|
@ -26,8 +26,8 @@
|
||||||
inkscape:pageopacity="1"
|
inkscape:pageopacity="1"
|
||||||
inkscape:pageshadow="2"
|
inkscape:pageshadow="2"
|
||||||
inkscape:zoom="1.4142136"
|
inkscape:zoom="1.4142136"
|
||||||
inkscape:cx="422.99272"
|
inkscape:cx="464.65225"
|
||||||
inkscape:cy="193.57419"
|
inkscape:cy="203.44926"
|
||||||
inkscape:document-units="px"
|
inkscape:document-units="px"
|
||||||
inkscape:current-layer="layer7"
|
inkscape:current-layer="layer7"
|
||||||
showgrid="true"
|
showgrid="true"
|
||||||
|
@ -2693,7 +2693,11 @@
|
||||||
sodipodi:role="line"
|
sodipodi:role="line"
|
||||||
id="tspan3445"
|
id="tspan3445"
|
||||||
x="37.24189"
|
x="37.24189"
|
||||||
y="388.43091">- Please also see documentation (especially the notes) in the *.md files</tspan></text>
|
y="388.43091">- Please also see documentation (especially the notes) in the *.md files</tspan><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
x="37.24189"
|
||||||
|
y="405.93091"
|
||||||
|
id="tspan3451">- Row and column assignments are to matrix positions, not physical positions</tspan></text>
|
||||||
</g>
|
</g>
|
||||||
<g
|
<g
|
||||||
inkscape:groupmode="layer"
|
inkscape:groupmode="layer"
|
||||||
|
|
Before Width: | Height: | Size: 151 KiB After Width: | Height: | Size: 152 KiB |
|
@ -41,6 +41,11 @@
|
||||||
NC o14-------15+ ADDR (see note)
|
NC o14-------15+ ADDR (see note)
|
||||||
|
|
||||||
* notes:
|
* notes:
|
||||||
|
* Row and column assignments are to matrix positions, which may or may
|
||||||
|
correspond to the physical position of the key: e.g. the key where `row4`
|
||||||
|
and `column2` cross will be scanned into the matrix at `[4][2]`, wherever
|
||||||
|
it happens to be located on the keyboard. Mapping from one to the other
|
||||||
|
(which only matters for defining layouts) is handled elsewhere.
|
||||||
* ADDR (pin15): Set slave address to `0b0100000` by connecting to Vss(GND).
|
* ADDR (pin15): Set slave address to `0b0100000` by connecting to Vss(GND).
|
||||||
* The user-defined bits are the three least significant
|
* The user-defined bits are the three least significant
|
||||||
* I2C addresses are 7 bits long (the last bit in the byte is used for
|
* I2C addresses are 7 bits long (the last bit in the byte is used for
|
||||||
|
|
|
@ -44,6 +44,11 @@
|
||||||
GND-------/
|
GND-------/
|
||||||
|
|
||||||
* notes:
|
* notes:
|
||||||
|
* Row and column assignments are to matrix positions, which may or may
|
||||||
|
correspond to the physical position of the key: e.g. the key where `row4`
|
||||||
|
and `column2` cross will be scanned into the matrix at `[4][2]`, wherever
|
||||||
|
it happens to be located on the keyboard. Mapping from one to the other
|
||||||
|
(which only matters for defining layouts) is handled elsewhere.
|
||||||
* SCL and SDA: Need external pull-up resistors. Sometimes the Teensy
|
* SCL and SDA: Need external pull-up resistors. Sometimes the Teensy
|
||||||
internal pull-ups are enough (see datasheet section 20.5.1), but i think
|
internal pull-ups are enough (see datasheet section 20.5.1), but i think
|
||||||
for this project we'll want external ones. The general recommendation
|
for this project we'll want external ones. The general recommendation
|
||||||
|
|
|
@ -143,7 +143,6 @@ _data_t linked_list_peek(_list_t * list, int index) {
|
||||||
* - success: the data field of the node at the given index
|
* - success: the data field of the node at the given index
|
||||||
* - failure: (_data_t) 0
|
* - failure: (_data_t) 0
|
||||||
*/
|
*/
|
||||||
// TODO
|
|
||||||
_data_t linked_list_pop(_list_t * list, int index) {
|
_data_t linked_list_pop(_list_t * list, int index) {
|
||||||
// if: no nodes exist
|
// if: no nodes exist
|
||||||
if (list->length == 0)
|
if (list->length == 0)
|
||||||
|
@ -164,100 +163,55 @@ _data_t linked_list_pop(_list_t * list, int index) {
|
||||||
node = list->head;
|
node = list->head;
|
||||||
list->head = node->next;
|
list->head = node->next;
|
||||||
} else {
|
} else {
|
||||||
// find the index-1'th node, then pop the next one
|
// find the index-1'th node
|
||||||
_node_t * previous;
|
_node_t * previous;
|
||||||
previous = list->head;
|
previous = list->head;
|
||||||
for (int i=1; i<index; i++)
|
for (int i=1; i<index; i++)
|
||||||
previous = previous->next;
|
previous = previous->next;
|
||||||
|
|
||||||
|
// if: last node
|
||||||
|
if (index == list->length-1)
|
||||||
|
list->tail = previous;
|
||||||
|
|
||||||
|
// pop the node at index
|
||||||
data = previous->next->data;
|
data = previous->next->data;
|
||||||
node = previous->next;
|
node = previous->next;
|
||||||
previous->next = node->next;
|
previous->next = node->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(node);
|
free(node);
|
||||||
|
|
||||||
|
list->length--;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* pop_head()
|
* find()
|
||||||
*
|
* TODO
|
||||||
* Returns
|
|
||||||
* - success: the data field of the first node of the list
|
|
||||||
* - failure: (_data_t) 0
|
|
||||||
*/
|
*/
|
||||||
_data_t linked_list_pop_head(_list_t * list) {
|
// TODO
|
||||||
if (list->length == 0)
|
|
||||||
return (_data_t) 0;
|
|
||||||
|
|
||||||
_node_t node = {
|
|
||||||
.data = list->head->data,
|
|
||||||
.next = list->head->next
|
|
||||||
};
|
|
||||||
|
|
||||||
free(list->head);
|
|
||||||
|
|
||||||
if (list->length == 1) {
|
|
||||||
list->head = NULL;
|
|
||||||
list->tail = NULL;
|
|
||||||
} else {
|
|
||||||
list->head = node.next;
|
|
||||||
}
|
|
||||||
|
|
||||||
list->length--;
|
|
||||||
return node.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* pop_tail()
|
|
||||||
*
|
|
||||||
* Returns
|
|
||||||
* - success: the data field of the last node of the list
|
|
||||||
* - failure: (_data_t) 0
|
|
||||||
*
|
|
||||||
* Note
|
|
||||||
* - This function is inefficient for singly linked lists: it has O(n) time
|
|
||||||
* instead of O(1) time like most of the other functions. But it's not
|
|
||||||
* needed for implementing stacks or queues, so i don't anticipate it being
|
|
||||||
* used all that much. It's here for completeness.
|
|
||||||
*/
|
|
||||||
_data_t linked_list_pop_tail(_list_t * list) {
|
|
||||||
if (list->length == 0)
|
|
||||||
return (_data_t) 0;
|
|
||||||
|
|
||||||
_node_t node = {
|
|
||||||
.data = list->tail->data,
|
|
||||||
.next = list->tail->next
|
|
||||||
};
|
|
||||||
|
|
||||||
free(list->tail);
|
|
||||||
|
|
||||||
if (list->length == 1) {
|
|
||||||
list->head = NULL;
|
|
||||||
list->tail = NULL;
|
|
||||||
} else {
|
|
||||||
list->tail = list->head;
|
|
||||||
for (uint8_t i=2; i<(list->length); i++)
|
|
||||||
list->tail = list->tail->next;
|
|
||||||
list->tail->next = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
list->length--;
|
|
||||||
return node.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* copy()
|
* copy()
|
||||||
*
|
*
|
||||||
* Returns
|
* Returns
|
||||||
* - success: a new pointer to a copy of the list who's pointer was passed
|
* - success: a new pointer to a (deep) copy of the list that was passed
|
||||||
* - failure: NULL
|
* - failure: NULL
|
||||||
*/
|
*/
|
||||||
_list_t * linked_list_copy(_list_t * list) {
|
_list_t * linked_list_copy(_list_t * list) {
|
||||||
_NEW_POINTER(_list_t, copy);
|
_NEW_POINTER(_list_t, copy);
|
||||||
if (!copy) return NULL;
|
if (!copy) return NULL;
|
||||||
|
|
||||||
for (uint8_t i=1; i<=(list->length); i++)
|
bool error;
|
||||||
linked_list_add_tail(copy, linked_list_read(list, i));
|
_node_t * node = list->head;
|
||||||
|
for (uint8_t i=0; i<(list->length); i++) {
|
||||||
|
error = ! linked_list_insert(copy, node->data, -1);
|
||||||
|
if (error) {
|
||||||
|
linked_list_free(copy);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
node = node->next;
|
||||||
|
}
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
@ -266,16 +220,14 @@ _list_t * linked_list_copy(_list_t * list) {
|
||||||
* free()
|
* free()
|
||||||
* - Free the memory allocated to all the nodes, then free the memory allocated
|
* - Free the memory allocated to all the nodes, then free the memory allocated
|
||||||
* to the list.
|
* to the list.
|
||||||
*
|
|
||||||
* Note
|
|
||||||
* - This is implemented inefficiently (using pop_head(), which does extra
|
|
||||||
* work). But that makes things simpler, and i don't anticipate using it all
|
|
||||||
* that often.
|
|
||||||
*/
|
*/
|
||||||
void linked_list_free(_list_t * list) {
|
void linked_list_free(_list_t * list) {
|
||||||
while ((list->length) > 0)
|
_node_t * node;
|
||||||
linked_list_pop_head(list);
|
for (uint8_t i=0; i<(list->length); i++) {
|
||||||
|
node = list->head;
|
||||||
|
list->head = list->head->next;
|
||||||
|
free(node);
|
||||||
|
}
|
||||||
free(list);
|
free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue