annotate include/PRU.h @ 16:670be80463a3 matrix_gpio

- analog matrixIn/matrixOut are now mapped as floats from 0 to 1 - use of an external PRU code can be enabled with -P <filename> - 16 channels of programmable GPIO can be accessed straight from render() either writing directly to the matrixGpio[] array or using digitalWrite(), digitalRead(), setDigitalDirection() macros from Utilities.h .
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 27 Apr 2015 13:01:57 +0100
parents 901d205d1a3c
children c98863e63174
rev   line source
andrewm@0 1 /*
andrewm@0 2 * PRU.h
andrewm@0 3 *
andrewm@0 4 * Created on: May 27, 2014
andrewm@0 5 * Author: andrewm
andrewm@0 6 */
andrewm@0 7
andrewm@0 8 #ifndef PRU_H_
andrewm@0 9 #define PRU_H_
andrewm@0 10
andrewm@0 11 #include <stdint.h>
andrewm@0 12
andrewm@0 13 class PRU
andrewm@0 14 {
andrewm@0 15 private:
andrewm@0 16 static const unsigned int kPruGPIODACSyncPin;
andrewm@0 17 static const unsigned int kPruGPIOADCSyncPin;
andrewm@0 18 static const unsigned int kPruGPIOTestPin;
andrewm@0 19 static const unsigned int kPruGPIOTestPin2;
andrewm@0 20 static const unsigned int kPruGPIOTestPin3;
andrewm@0 21
andrewm@0 22 public:
andrewm@0 23 // Constructor
andrewm@0 24 PRU();
andrewm@0 25
andrewm@0 26 // Destructor
andrewm@0 27 ~PRU();
andrewm@0 28
andrewm@0 29 // Prepare the GPIO pins needed for the PRU
giuliomoro@16 30 int prepareGPIO(int use_spi, int use_matrix_gpio, int include_test_pin, int include_led);
andrewm@0 31
andrewm@0 32 // Clean up the GPIO at the end
andrewm@0 33 void cleanupGPIO();
andrewm@0 34
andrewm@0 35 // Initialise and open the PRU
andrewm@12 36 int initialise(int pru_num, int frames_per_buffer, int spi_channels,
andrewm@12 37 bool xenomai_test_pin = false);
andrewm@0 38
andrewm@15 39 // Run the code image in pru_rtaudio_bin.h
giuliomoro@16 40 int start(char * const filename);
andrewm@0 41
andrewm@0 42 // Loop: read and write data from the PRU
andrewm@0 43 void loop();
andrewm@0 44
andrewm@0 45 // Wait for an interrupt from the PRU indicate it is finished
andrewm@0 46 void waitForFinish();
andrewm@0 47
andrewm@0 48 // Turn off the PRU when done
andrewm@0 49 void disable();
andrewm@0 50
andrewm@0 51 // For debugging:
andrewm@0 52 void setGPIOTestPin();
andrewm@0 53 void clearGPIOTestPin();
andrewm@0 54
andrewm@0 55 private:
andrewm@0 56 int pru_number; // Which PRU we use
andrewm@0 57 bool running; // Whether the PRU is running
andrewm@0 58 bool spi_enabled; // Whether SPI ADC and DAC are used
giuliomoro@16 59 bool matrix_gpio_enabled; // Whether Matrix GPIO is used
andrewm@0 60 bool gpio_enabled; // Whether GPIO has been prepared
andrewm@0 61 bool led_enabled; // Whether a user LED is enabled
andrewm@0 62 bool gpio_test_pin_enabled; // Whether the test pin was also enabled
andrewm@12 63 int spi_num_channels; // How many channels to use for SPI ADC/DAC
andrewm@0 64
andrewm@0 65 volatile uint32_t *pru_buffer_comm;
andrewm@0 66 uint16_t *pru_buffer_spi_dac;
andrewm@0 67 uint16_t *pru_buffer_spi_adc;
giuliomoro@16 68 uint32_t *pru_buffer_matrix_gpio;
andrewm@0 69 int16_t *pru_buffer_audio_dac;
andrewm@0 70 int16_t *pru_buffer_audio_adc;
andrewm@0 71 unsigned int spi_buffer_frames;
giuliomoro@16 72 unsigned int matrix_gpio_buffer_frames;
andrewm@0 73 unsigned int audio_buffer_frames;
andrewm@0 74
andrewm@0 75 int xenomai_gpio_fd; // File descriptor for /dev/mem for fast GPIO
andrewm@0 76 uint32_t *xenomai_gpio; // Pointer to GPIO registers
andrewm@0 77 };
andrewm@0 78
andrewm@0 79
andrewm@0 80 #endif /* PRU_H_ */