Change definition of NO_PIN to 1+PIN_MAX (#1231)

Fixes bug #1228 that gpio 0 could not be used by the linuxgpio system.

* Add sanity checks
* Loop over defined pins only

Co-authored-by: Stefan Rueger <stefan.rueger@urclocks.com>
This commit is contained in:
Bas Wijnen
2023-01-02 15:23:01 +01:00
committed by GitHub
parent b6d50ef0a9
commit dc0ab33a58
13 changed files with 125 additions and 87 deletions

View File

@@ -1198,8 +1198,12 @@ static void buspirate_bb_enable(PROGRAMMER *pgm, const AVRPART *p) {
*/
static int buspirate_bb_getpin(const PROGRAMMER *pgm, int pinfunc) {
unsigned char buf[10];
int value = 0;
int pin = pgm->pinno[pinfunc];
int pin, value = 0;
if(pinfunc < 0 || pinfunc >= N_PINS)
return -1;
pin = pgm->pinno[pinfunc];
if (pin & PIN_INVERSE) {
pin &= PIN_MASK;
@@ -1261,6 +1265,9 @@ static int buspirate_bb_setpin_internal(const PROGRAMMER *pgm, int pin, int valu
}
static int buspirate_bb_setpin(const PROGRAMMER *pgm, int pinfunc, int value) {
if(pinfunc < 0 || pinfunc >= N_PINS)
return -1;
return buspirate_bb_setpin_internal(pgm, pgm->pinno[pinfunc], value);
}