mirror of
https://github.com/tdaede/td-io.git
synced 2024-11-28 00:20:51 +01:00
Add JVS chaining support.
Also fix DIP assignments.
This commit is contained in:
parent
d2af37b436
commit
4f1661661b
@ -10,7 +10,8 @@ const uint PIN_JVS_SENSE_2_5V = 14;
|
|||||||
const uint PIN_JVS_SENSE_0V = 13;
|
const uint PIN_JVS_SENSE_0V = 13;
|
||||||
|
|
||||||
const uint PIN_JVS_TERMINATION = 15;
|
const uint PIN_JVS_TERMINATION = 15;
|
||||||
const uint PIN_JVS_SENSE_IN = 26;
|
const uint PIN_JVS_SENSE_IN_HIGH = 11;
|
||||||
|
const uint PIN_JVS_SENSE_IN_LOW = 12;
|
||||||
|
|
||||||
const uint PIN_SR_DATA = 20;
|
const uint PIN_SR_DATA = 20;
|
||||||
const uint PIN_SR_CLK = 18;
|
const uint PIN_SR_CLK = 18;
|
||||||
@ -22,8 +23,8 @@ const uint PIN_LOCKOUT1 = 10;
|
|||||||
const uint PIN_LOCKOUT2 = 9;
|
const uint PIN_LOCKOUT2 = 9;
|
||||||
|
|
||||||
const uint PIN_LED_ENUMERATED = PICO_DEFAULT_LED_PIN;
|
const uint PIN_LED_ENUMERATED = PICO_DEFAULT_LED_PIN;
|
||||||
const uint PIN_DIP1 = 16;
|
const uint PIN_DIP1 = 17;
|
||||||
const uint PIN_DIP2 = 17;
|
const uint PIN_DIP2 = 16;
|
||||||
|
|
||||||
const uint16_t JVS_TERMINATION_THRESHOLD = (uint16_t)(3.75/2.0/3.3*4096);
|
const uint16_t JVS_TERMINATION_THRESHOLD = (uint16_t)(3.75/2.0/3.3*4096);
|
||||||
const uint16_t JVS_0V_THRESHOLD = (uint16_t)(1.25/2.0/3.3*4096);
|
const uint16_t JVS_0V_THRESHOLD = (uint16_t)(1.25/2.0/3.3*4096);
|
||||||
@ -75,7 +76,7 @@ uint8_t prev_coin_p2 = 0;
|
|||||||
#define SR_TILT 29
|
#define SR_TILT 29
|
||||||
|
|
||||||
const uint8_t JVS_COMM_VER = 0x10;
|
const uint8_t JVS_COMM_VER = 0x10;
|
||||||
const char id_str[] = "TD;TD-IO;v1.0;https://github.com/tdaede/td-io";
|
const char id_str[] = "TD;TD-IO;v1.1;https://github.com/tdaede/td-io";
|
||||||
|
|
||||||
const uint8_t input_desc_1coin[] = {
|
const uint8_t input_desc_1coin[] = {
|
||||||
0x01, 2, 12, 0,
|
0x01, 2, 12, 0,
|
||||||
@ -162,9 +163,7 @@ uint32_t read_switches() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void update_termination() {
|
void update_termination() {
|
||||||
uint16_t v = adc_read();
|
if (gpio_get(PIN_JVS_SENSE_IN_HIGH)) {
|
||||||
v = 4095; // FIXME: bad adc input
|
|
||||||
if (v >= JVS_TERMINATION_THRESHOLD) {
|
|
||||||
gpio_put(PIN_JVS_TERMINATION, 0);
|
gpio_put(PIN_JVS_TERMINATION, 0);
|
||||||
} else {
|
} else {
|
||||||
gpio_put(PIN_JVS_TERMINATION, 1);
|
gpio_put(PIN_JVS_TERMINATION, 1);
|
||||||
@ -214,9 +213,12 @@ int main() {
|
|||||||
gpio_init(PIN_JVS_TERMINATION);
|
gpio_init(PIN_JVS_TERMINATION);
|
||||||
gpio_put(PIN_JVS_TERMINATION, 1); // disable termination by default
|
gpio_put(PIN_JVS_TERMINATION, 1); // disable termination by default
|
||||||
gpio_set_dir(PIN_JVS_TERMINATION, GPIO_OUT);
|
gpio_set_dir(PIN_JVS_TERMINATION, GPIO_OUT);
|
||||||
adc_init();
|
gpio_init(PIN_JVS_SENSE_IN_LOW);
|
||||||
adc_gpio_init(PIN_JVS_SENSE_IN);
|
gpio_set_dir(PIN_JVS_SENSE_IN_LOW, GPIO_IN);
|
||||||
adc_select_input(0);
|
gpio_pull_up(PIN_JVS_SENSE_IN_LOW);
|
||||||
|
gpio_init(PIN_JVS_SENSE_IN_HIGH);
|
||||||
|
gpio_set_dir(PIN_JVS_SENSE_IN_HIGH, GPIO_IN);
|
||||||
|
gpio_pull_up(PIN_JVS_SENSE_IN_HIGH);
|
||||||
|
|
||||||
// sr
|
// sr
|
||||||
gpio_init(PIN_SR_DATA);
|
gpio_init(PIN_SR_DATA);
|
||||||
@ -287,10 +289,9 @@ int main() {
|
|||||||
uint8_t node_id = message[i+1];
|
uint8_t node_id = message[i+1];
|
||||||
i += 2;
|
i += 2;
|
||||||
printf("Assign node id N: %02x\n", node_id);
|
printf("Assign node id N: %02x\n", node_id);
|
||||||
uint16_t v = adc_read();
|
if ((our_address == 0)
|
||||||
printf("Reading ADC: %d\n", v);
|
&& (gpio_get(PIN_JVS_SENSE_IN_HIGH)
|
||||||
v = 4095; // FIXME: adc circuit is bad
|
|| !gpio_get(PIN_JVS_SENSE_IN_LOW))) {
|
||||||
if ((v >= JVS_TERMINATION_THRESHOLD) || (v < JVS_0V_THRESHOLD)) {
|
|
||||||
printf("Assigning our address\n");
|
printf("Assigning our address\n");
|
||||||
our_address = node_id;
|
our_address = node_id;
|
||||||
msg_send[o] = JVS_REPORT_GOOD;
|
msg_send[o] = JVS_REPORT_GOOD;
|
||||||
@ -333,7 +334,7 @@ int main() {
|
|||||||
printf("Got input descriptor request\n");
|
printf("Got input descriptor request\n");
|
||||||
msg_send[o] = JVS_REPORT_GOOD;
|
msg_send[o] = JVS_REPORT_GOOD;
|
||||||
o++;
|
o++;
|
||||||
if (gpio_get(PIN_DIP1)) {
|
if (!gpio_get(PIN_DIP1)) {
|
||||||
memcpy(&msg_send[o], input_desc_1coin, sizeof(input_desc_1coin));
|
memcpy(&msg_send[o], input_desc_1coin, sizeof(input_desc_1coin));
|
||||||
o += sizeof(input_desc_1coin);
|
o += sizeof(input_desc_1coin);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user