-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import logging | ||
|
||
from .common import set_bit | ||
|
||
class AUXPin(): | ||
""" | ||
Auxilary pin base class | ||
This class is meant to be used in any mode and is instanciated in the | ||
Protocol class | ||
:example: | ||
>>> import pyHydrabus | ||
>>> i=pyHydrabus.I2C('/dev/hydrabus') | ||
>>> # Set AUX pin 0 (PC4) to output | ||
>>> i.AUX[0].direction = 0 | ||
>>> # Set AUX pin to logical 1 | ||
>>> i.AUX[0].value = 1 | ||
>>> # Read Auxiliary pin 2 (PC5) value | ||
>>> i.AUX[1].value | ||
""" | ||
|
||
OUTPUT = 0 | ||
INPUT = 1 | ||
|
||
def __init__(self, number, hydrabus): | ||
""" | ||
AUXPin constructor | ||
:param number: Auxilary pin number (0-3) | ||
:param hydrabus: Initialized pyHydrabus.Hydrabus instance | ||
""" | ||
self.number = number | ||
self._hydrabus = hydrabus | ||
self._logger = logging.getLogger(__name__) | ||
|
||
def _get_config(self): | ||
""" | ||
Gets Auxiliary pin config from Hydrabus | ||
:return: Auxilary pin config (4 bits pullup for AUX[0-3], 4 bits value for AUX[0-3]) | ||
:rtype: byte | ||
""" | ||
CMD = 0b11100000 | ||
self._hydrabus.write(CMD.to_bytes(1, byteorder="big")) | ||
return self._hydrabus.read(1) | ||
|
||
def _get_values(self): | ||
""" | ||
Gets Auxiliary pin values from Hydrabus | ||
:return: Auxilary pin values AUX[0-3] | ||
:rtype: byte | ||
""" | ||
CMD = 0b11000000 | ||
self._hydrabus.write(CMD.to_bytes(1, byteorder="big")) | ||
return self._hydrabus.read(1) | ||
|
||
@property | ||
def value(self): | ||
""" | ||
Auxiliary pin getter | ||
""" | ||
return (ord(self._get_values()) >> self.number) & 0b1 | ||
|
||
@value.setter | ||
def value(self, value): | ||
""" | ||
Auxiliary pin setter | ||
:param value: auxiliary pin value (0 or 1) | ||
""" | ||
CMD = 0b11010000 | ||
CMD = CMD | ord(set_bit(self._get_values(), value, self.number)) | ||
self._hydrabus.write(CMD.to_bytes(1, byteorder="big")) | ||
if self._hydrabus.read(1) == b"\x01": | ||
return | ||
else: | ||
self._logger.error("Error setting auxiliary pins value.") | ||
|
||
@property | ||
def direction(self): | ||
""" | ||
Auxiliary pin direction getter | ||
:return: The pin direction (0=output, 1=input) | ||
:rtype: int | ||
""" | ||
return (ord(self._get_config()) >> self.number) & 0b1 | ||
|
||
@direction.setter | ||
def direction(self, value): | ||
""" | ||
Auxiliary pin direction setter | ||
:param value: The pin direction (0=output, 1=input) | ||
""" | ||
CMD = 0b11110000 | ||
PARAM = self._get_config() | ||
PARAM = set_bit(PARAM, value, self.number) | ||
|
||
self._hydrabus.write(CMD.to_bytes(1, byteorder="big")) | ||
self._hydrabus.write(PARAM) | ||
if self._hydrabus.read(1) == b"\x01": | ||
return | ||
else: | ||
self._logger.error("Error setting auxiliary pins direction.") | ||
|
||
@property | ||
def pullup(self): | ||
""" | ||
Auxiliary pin pullup getter | ||
:return: Auxiliary pin pullup status (1=enabled, 0=disabled") | ||
:rtype: int | ||
""" | ||
return (ord(self._get_config()) >> (4 + self.number)) & 0b1 | ||
|
||
@pullup.setter | ||
def pullup(self, value): | ||
""" | ||
Auxiliary pin pullup setter | ||
:param value: Auxiliary pin pullup (1=enabled, 0=disabled") | ||
""" | ||
CMD = 0b11110000 | ||
PARAM = self._get_config() | ||
PARAM = set_bit(PARAM, value, 4+self.number) | ||
|
||
self._hydrabus.write(CMD.to_bytes(1, byteorder="big")) | ||
self._hydrabus.write(PARAM) | ||
if self._hydrabus.read(1) == b"\x01": | ||
return | ||
else: | ||
self._logger.error("Error setting auxiliary pins value.") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* HydraBus/HydraNFC | ||
* | ||
* Copyright (C) 2014-2019 Benjamin VERNOUX | ||
* Copyright (C) 2019 Nicolas OBERLI | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "common.h" | ||
#include "tokenline.h" | ||
#include "stm32f4xx_hal.h" | ||
|
||
#include "hydrabus_bbio.h" | ||
#include "hydrabus_bbio_aux.h" | ||
#include "bsp_gpio.h" | ||
|
||
void bbio_aux_init_proto_default(t_hydra_console *con) | ||
{ | ||
mode_config_proto_t* proto = &con->mode->proto; | ||
|
||
//Default to input no pullup | ||
proto->aux_config = 0b00001111; | ||
|
||
bbio_aux_mode_set(con); | ||
} | ||
|
||
uint8_t bbio_aux_mode_get(t_hydra_console *con) | ||
{ | ||
mode_config_proto_t* proto = &con->mode->proto; | ||
return proto->aux_config; | ||
} | ||
|
||
void bbio_aux_mode_set(t_hydra_console *con) | ||
{ | ||
mode_config_proto_t* proto = &con->mode->proto; | ||
|
||
mode_dev_gpio_mode_t mode; | ||
mode_dev_gpio_pull_t pull; | ||
uint8_t i=0; | ||
|
||
for(i=0; i<4; i++) { | ||
if( (proto->aux_config >> i) & 0b1) { | ||
mode = MODE_CONFIG_DEV_GPIO_IN; | ||
} else { | ||
mode = MODE_CONFIG_DEV_GPIO_OUT_PUSHPULL; | ||
} | ||
if( (proto->aux_config >> (4 + i)) & 0b1) { | ||
pull = MODE_CONFIG_DEV_GPIO_PULLUP; | ||
} else { | ||
pull = MODE_CONFIG_DEV_GPIO_NOPULL; | ||
} | ||
bsp_gpio_init(BSP_GPIO_PORTC, 4+i, mode, pull); | ||
} | ||
} | ||
|
||
uint8_t bbio_aux_read(void) | ||
{ | ||
uint16_t data; | ||
data = bsp_gpio_port_read(BSP_GPIO_PORTC); | ||
return (uint8_t)(data>>4) & 0b1111; | ||
} | ||
|
||
void bbio_aux_write(uint8_t command) | ||
{ | ||
uint8_t i=0; | ||
for(i=0; i<4; i++){ | ||
if((command>>i)&1){ | ||
bsp_gpio_set(BSP_GPIO_PORTC, 4+i); | ||
}else{ | ||
bsp_gpio_clr(BSP_GPIO_PORTC, 4+i); | ||
} | ||
} | ||
} | ||
|
||
uint8_t bbio_aux(t_hydra_console *con, uint8_t command) | ||
{ | ||
mode_config_proto_t* proto = &con->mode->proto; | ||
|
||
uint8_t config; | ||
|
||
switch(command & 0b11110000){ | ||
case BBIO_AUX_MODE_READ: | ||
return bbio_aux_mode_get(con); | ||
case BBIO_AUX_MODE_SET: | ||
chnRead(con->sdu, &config, 1); | ||
proto->aux_config = config; | ||
bbio_aux_mode_set(con); | ||
return 1; | ||
case BBIO_AUX_READ: | ||
return bbio_aux_read(); | ||
case BBIO_AUX_WRITE: | ||
bbio_aux_write(command); | ||
return 1; | ||
default: | ||
return 0; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* HydraBus/HydraNFC | ||
* | ||
* Copyright (C) 2019 Nicolas OBERLI | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
void bbio_aux_init_proto_default(t_hydra_console *con); | ||
uint8_t bbio_aux_mode_get(t_hydra_console *con); | ||
void bbio_aux_mode_set(t_hydra_console *con); | ||
uint8_t bbio_aux_read(void); | ||
void bbio_aux_write(uint8_t command); | ||
uint8_t bbio_aux(t_hydra_console *con, uint8_t command); |
3 comments
on commit 858de3f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks to rename aux.py to other name as there is a conflict on windows with aux. files see uncomplicate/neanderthal#53
see also BeyondTheClouds/VMPlaceS#10
Result is when we do on windows a git clone on hydrafw there is error unable to create file contrib/pyHydrabus/pyHydrabus/aux.py: No such file or directory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 96ce104
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect I confirm git now work again with master
Quote me