Functions | |
def | portA |
def | ddrA |
def | digitalRead |
def | digitalWrite |
def | delay |
Provides generic access to the AVR microcontroller
Note that to save RAM when the module is imported, many of the port & ddr methods below are commented out. Uncomment and recompile in order to use!
USAGE
import avr avr.ddrA(0) # Set all pins as input a = avr.portA() avr.ddrA(0xFF) # Set all pins as output avr.portA(42) avr.delay(500) # Half second pause if avr.digitalRead('A', 3): avr.digitalWrite('D', 0, True)
def avr::delay | ( | ms | ) |
__NATIVE__ PmReturn_t retval = PM_RET_OK; if(NATIVE_GET_NUM_ARGS() != 1) { PM_RAISE(retval, PM_RET_EX_TYPE); return retval; } pPmObj_t pa = NATIVE_GET_LOCAL(0); if (OBJ_GET_TYPE(pa) == OBJ_TYPE_INT) { _delay_ms((double) ((pPmInt_t)pa)->val); } else if (OBJ_GET_TYPE(pa) == OBJ_TYPE_FLT) { _delay_ms((double) ((pPmFloat_t)pa)->val); } else { PM_RAISE(retval, PM_RET_EX_TYPE); } NATIVE_SET_TOS(PM_NONE); return retval;
def avr::digitalRead | ( | port, | ||
pin | ||||
) |
__NATIVE__ volatile uint8_t *port; volatile uint8_t *direction; uint8_t pin; PmReturn_t retval = PM_RET_OK; if(NATIVE_GET_NUM_ARGS() != 2) { PM_RAISE(retval, PM_RET_EX_TYPE); return retval; } retval = _get_port_register(&port, NULL, &direction, &pin); if(retval != PM_RET_OK) return retval; *direction &= ~(1<<pin); // Set pin to input pPmObj_t pa = (*port & (1<<pin)) ? PM_TRUE : PM_FALSE; NATIVE_SET_TOS(pa); // Push our result object onto the stack return retval;
def avr::digitalWrite | ( | port, | ||
pin, | ||||
value | ||||
) |
__NATIVE__ volatile uint8_t *port; volatile uint8_t *direction; uint8_t pin; pPmObj_t pc; PmReturn_t retval = PM_RET_OK; NATIVE_SET_TOS(PM_NONE); if(NATIVE_GET_NUM_ARGS() != 3) { PM_RAISE(retval, PM_RET_EX_TYPE); return retval; } retval = _get_port_register(NULL, &port, &direction, &pin); if(retval != PM_RET_OK) return retval; pc = NATIVE_GET_LOCAL(2); /* If the arg is not an integer, raise TypeError */ if (OBJ_GET_TYPE(pc) != OBJ_TYPE_INT && OBJ_GET_TYPE(pc) != OBJ_TYPE_BOOL) { PM_RAISE(retval, PM_RET_EX_TYPE); return retval; } *direction |= (1<<pin); // Set pin to output if(((pPmInt_t)pc)->val) *port |= 1<<pin; else *port &= ~(1<<pin); return retval;
def avr::portA | ( | a | ) |