Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pin order as build options #120

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions NetworkModule/Gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "gpio.h"
#include "main.h"
#include "uipopt.h"
#include "build_options.h"

extern uint8_t stored_magic4; // MSB Magic Number stored in EEPROM
extern uint8_t stored_magic3; //
Expand All @@ -52,6 +53,10 @@ extern uint8_t stored_pin_control[16]; // Per pin control settings stored in
volatile struct io_registers io_reg[ NUM_PORTS ] @0x5000; // make room for PA .. PG starting at 0x5000

// Define the pair PORT:BIT for each of the 16 I/Os
#if IO_PIN_ORDER == 1
// HW-584
// 5V 16 15 14 13 12 11 10 09 G
// 5V 08 07 06 05 04 03 02 01 G
const struct io_mapping io_map[16] = {
{ PA, 0x08 }, // PA bit3, IO1
{ PA, 0x20 }, // PA bit5, IO2
Expand All @@ -70,6 +75,65 @@ const struct io_mapping io_map[16] = {
{ PG, 0x01 }, // PG bit0, IO15
{ PC, 0x40 } // PC bit6, IO16
};
#endif IO_PIN_ORDER == 1

#if IO_PIN_ORDER == 2
// HW-584
// 5V 16 15 14 13 12 11 10 09 G
// 5V 08 07 06 05 04 03 02 01 G
//
// relay:
// 5V 02 04 06 08 10 12 14 16 G
// 5V 01 03 05 07 09 11 13 15 G
//
const struct io_mapping io_map[16] = {
{ PC, 0x80 }, // PC bit7, IO01
{ PC, 0x40 }, // PC bit6, IO02
{ PG, 0x02 }, // PG bit1, IO03
{ PG, 0x01 }, // PG bit0, IO04
{ PE, 0x01 }, // PE bit0, IO05
{ PE, 0x08 }, // PE bit3, IO06
{ PD, 0x04 }, // PD bit2, IO07
{ PD, 0x01 }, // PD bit0, IO08
{ PD, 0x10 }, // PD bit4, IO09
{ PD, 0x08 }, // PD bit3, IO10
{ PD, 0x40 }, // PD bit6, IO11
{ PD, 0x20 }, // PD bit5, IO12
{ PA, 0x20 }, // PA bit5, IO13
{ PD, 0x80 }, // PD bit7, IO14
{ PA, 0x08 }, // PA bit3, IO15
{ PA, 0x10 } // PA bit4, IO16
};
#endif IO_PIN_ORDER == 2

#if IO_PIN_ORDER == 3
// HW-584
// 5V 16 15 14 13 12 11 10 09 G
// 5V 08 07 06 05 04 03 02 01 G
//
// relay:
// 5V 08 07 06 05 04 03 02 01 G
// -- -- -- -- -- -- -- -- -- -
//
const struct io_mapping io_map[16] = {
{ PA, 0x10 }, // PA bit4, IO01
{ PD, 0x80 }, // PD bit7, IO02
{ PD, 0x20 }, // PD bit5, IO03
{ PD, 0x08 }, // PD bit3, IO04
{ PD, 0x01 }, // PD bit0, IO05
{ PE, 0x08 }, // PE bit3, IO06
{ PG, 0x01 }, // PG bit0, IO07
{ PC, 0x40 }, // PC bit6, IO08
{ PA, 0x08 }, // PA bit3, IO09
{ PA, 0x20 }, // PA bit5, IO10
{ PD, 0x40 }, // PD bit6, IO11
{ PD, 0x10 }, // PD bit4, IO12
{ PD, 0x04 }, // PD bit2, IO13
{ PE, 0x01 }, // PE bit0, IO14
{ PG, 0x02 }, // PG bit1, IO15
{ PC, 0x80 } // PC bit7, IO16
};
#endif IO_PIN_ORDER == 3


void gpio_init(void)
Expand Down
3 changes: 2 additions & 1 deletion NetworkModule/Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include <stdlib.h>

#include "build_options.h"
#include "main.h"
#include "Enc28j60.h"
#include "Spi.h"
Expand Down Expand Up @@ -4084,7 +4085,7 @@ void check_runtime_changes(void)
// received.

// Check all pin_control bytes for changes.
// ON/OFF state: If an Output pins ON/OFF state changes the EEPROM is
// ON/OFF state: If an Output pin’s ON/OFF state changes the EEPROM is
// updated only if Retain is set, but a restart must not occur.
// IMPORTANT: This routine must only change Output pin ON/OFF states.
// The read_input_pins() function is the only place where Input pin
Expand Down
48 changes: 48 additions & 0 deletions NetworkModule/build_options.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Build options for Network module firmware
*
* Author: P-O Yliniemi
* Email: [email protected]
*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __BUILD_OPTIONS_H__
#define __BUILD_OPTIONS_H__

// IO pin order, used in gpio.c to set up the io_mapping structure
//
// HW-584 silkscreen pin order
//
// 5V 16 15 14 13 12 11 10 09 G
// 5V 08 07 06 05 04 03 02 01 G
// #define IO_PIN_ORDER 1

//
// Typical 16 channel board pin order
//
// 5V 02 04 06 08 10 12 14 16 G
// 5V 01 03 05 07 09 11 13 15 G
//
#define IO_PIN_ORDER 2

//
// Pin order for 8 channel relay board when using inner row for relays
// (use the default pin order if using the outer row)
//
// 5V 08 07 06 05 04 03 02 01 G
// -- -- -- -- -- -- -- -- -- -
//
// #define IO_PIN_ORDER 3

#endif