Alvaro Cassinelli
/
laserScannerControl_FRDMK64F
Example controlling galvanomirrors (X and Y) using the spi DAC MCP4922 and the new platform FRDM_K64F
Diff: laserProjectorHardware/laserProjectorHardware.h
- Revision:
- 0:26b228dde70c
- Child:
- 2:383b2acec6e4
diff -r 000000000000 -r 26b228dde70c laserProjectorHardware/laserProjectorHardware.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/laserProjectorHardware/laserProjectorHardware.h Sun May 25 11:28:28 2014 +0000 @@ -0,0 +1,73 @@ + +#ifndef hardwareIO_h +#define hardwareIO_h + +#include "mbed.h" + + +//SPI library (for ADC MCP4922 chip) uses the following pins, but we don't have to set them and inputs or outputs +// (this is done when the library is initialized, which is done by pre-instantiation: +#define SCK_PIN D13 //SPI Clock +#define MISO_PIN D12 //SPI input (data comming from DAC, here not connected) +#define MOSI_PIN D11 //SPI output (data going to DAC) + +//**** CHIP SELECT pins for MP4922 DAC (mirrors and red laser) +// VERY IMPORTANT: the chip select for the DACs should be different from the default SPI "SS" pin (Slave Select), which is 53 by default (and will be used by the Ethernet Shield). +#define CS_DAC_MIRRORS D7 //Chip Select of the first DAC (mirrors) + +//**** LASERS pins: +#define LASER_RED_PIN D8 // USED (TTL control). +#define LASER_GREEN_PIN D9 // NOT YET USED USED (TTL control) +#define LASER_BLUE_PIN D10 // NOT YET USED USED (TTL control) + +//**** MIRRORS: +//The DAC is 12 bytes capable (Max=4096), but we will limit this a little. +#define MAX_AD_MIRRORS 4095 // note: 4095 is the absolute maximum for the SPI voltage (5V). This is for checking hardware compliance, but max and min angles can be defined for X and Y in each LivingSpot instance. +#define MIN_AD_MIRRORS 0 // note: 0 is 0 volts for the SPI voltage. +// We assume that the center of the mirror is at MAX_AD_MIRRORS/2 = 2000: +#define CENTER_AD_MIRROR_X 2047 // This MUST BE the direction of the photodetector. +#define CENTER_AD_MIRROR_Y 2047 // This MUST BE the direction of the photodetector. + + +extern DigitalOut Laser_Red, Laser_Green, Laser_Blue; + +// ================================================================================================================================================================== + +class HardwareIO { +public: + + + void init(void); + + void showLimitsMirrors( int times ); + + // SPI control for DAC for mirrors and red laser power (low level): + void writeOutX(unsigned short value); + void writeOutY(unsigned short value); + void writeOutXY(unsigned short valueX, unsigned short valueY) {writeOutX(valueX); writeOutY(valueY);}; + + + //Displaying lasers: + // Again: for the moment laser are TTL but these could be analog. Now, it is just: powerValue > 0 ==> 'true'; else 'false' + // Red laser: + void setRedPower(int powerRed); + // Green laser: + void setGreenPower(int powerGreen); + // Blue laser: + void setBluePower(int powerBlue); + // Setting all colors at once: + void setRGBPower(unsigned char color); // we will use the 3 LSB bits to set each color + + + +private: + +}; + + +extern HardwareIO IO; // allows the object IO to be used in other .cpp files (IO is pre-instantiated in hardwareIO.cpp) +// NOTE: IO encapsulates many IO functions, but perhaps it is better not to have an IO object - just use each IO function separatedly (as with pc object for instance) +extern Serial pc; // allows pc to be manipulated by other .cpp files, even if pc is defined in the hardwareIO.cpp + + +#endif