Exemplo n.º 1
0
char pfio_digital_read(char pin_number)
{
    char current_pin_values = pfio_read_input();
    char pin_bit_mask = pfio_get_pin_bit_mask(pin_number);
    // note: when using bitwise operators and checking if a mask is
    // in there it is always better to check if the result equals
    // to the desidered mask, in this case pin_bit_mask.
    return ( current_pin_values & pin_bit_mask ) == pin_bit_mask;
}
Exemplo n.º 2
0
Arquivo: pfio.c Projeto: AndyA/piface
void pfio_digital_write(char pin_number, char value)
{
    char pin_bit_mask = pfio_get_pin_bit_mask(pin_number);
    char old_pin_values = pfio_read_output();

    char new_pin_values;
    if (value > 0)
        new_pin_values = old_pin_values | pin_bit_mask;
    else
        new_pin_values = old_pin_values & ~pin_bit_mask;

#ifdef VERBOSE_MODE
    printf("digital_write: pin number %d, value %d\n", pin_number, value);
    printf("pin bit mask: 0x%x\n", pin_bit_mask);
    printf("old pin values: 0x%x\n", old_pin_values);
    printf("new pin values: 0x%x\n", new_pin_values);
    printf("\n");
#endif

    pfio_write_output(new_pin_values);
}
Exemplo n.º 3
0
Arquivo: pfio.c Projeto: AndyA/piface
char pfio_digital_read(char pin_number)
{
    char current_pin_values = pfio_read_input();
    char pin_bit_mask = pfio_get_pin_bit_mask(pin_number);
    return (current_pin_values & pin_bit_mask) > 0;
}