示例#1
0
// updates an entire row of LEDs
void updateRow(int y) {
	int temp;
	for (int x = 0; x < NUM_COLS; x++)
	{
		PIOB->PIO_CODR = COLOR2_MASK | CLK_MASK;
		PIOC->PIO_CODR = COLOR1_MASK;
		temp = (uint32_t)display[y][x] << 22;
		PIOC->PIO_SODR = temp & COLOR1_MASK;
		temp = (uint32_t)display[y][x] << 6;
		PIOB->PIO_SODR = (temp & COLOR2_MASK) | CLK_MASK;
	}
	// toggle latch
	pinOutput(LAT_PIN, 1); 
	pinOutput(LAT_PIN, 0);
	
	// This seems like it'd be slow, but gets optimized nicely
	PIOB->PIO_CODR = ADDR_MASK;
	temp = 0;
	if (y & (1 << 0))
		temp |= (1 << 4);
	if (y & (1 << 1))
		temp |= (1 << 5);
	if (y & (1 << 2))
		temp |= (1 << 2);
	if (y & (1 << 3))
		temp |= (1 << 3);
	PIOB->PIO_SODR = temp;
}
示例#2
0
//timer interrupt handler
void TC3_Handler()
{
	long dummy = REG_TC1_SR0;
	pinOutput(OE_PIN, 0); // set OE low
	for (int i = 0; i < 16; i++)
	{
      updateRow(i);
	}
	pinOutput(OE_PIN, 1); // set OE high
}
示例#3
0
/*----------------------------------------------------------------------------*/
static enum Result interfaceInit(void *object, const void *configBase)
{
  const struct InterfaceWrapperConfig * const config = configBase;
  struct InterfaceWrapper * const interface = object;

  interface->pipe = config->pipe;
  interface->rx = pinInit(config->rx);
  assert(pinValid(interface->rx));
  pinOutput(interface->rx, 0);
  interface->tx = pinInit(config->tx);
  assert(pinValid(interface->tx));
  pinOutput(interface->tx, 0);

  return E_OK;
}
示例#4
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  const struct Pin led = pinInit(LED_PIN);
  pinOutput(led, false);

  struct Interface * const adc = init(AdcOneShot, &adcConfig);
  assert(adc);

  struct Timer * const timer = init(GpTimer, &timerConfig);
  assert(timer);
  timerSetOverflow(timer, 1000);

  bool event = false;
  timerSetCallback(timer, onTimerOverflow, &event);
  timerEnable(timer);

  while (1)
  {
    while (!event)
      barrier();
    event = false;

    pinSet(led);

    uint16_t voltage;
    const size_t bytesRead = ifRead(adc, &voltage, sizeof(voltage));
    assert(bytesRead == sizeof(voltage));
    (void)bytesRead; /* Suppress warning */

    pinReset(led);
  }

  return 0;
}
示例#5
0
LastUpdatedInputNode::LastUpdatedInputNode( QSharedPointer<fugio::NodeInterface> pNode )
	: NodeControlBase( pNode )
{
	mPinInput = pinInput( "Input 1" );

	mPinOutput = pinOutput( "Output", next_uuid() );
}
示例#6
0
void initializeDisplay()
{
	pinMode(R1_PIN,OUTPUT);
	pinMode(G1_PIN,OUTPUT);
	pinMode(B1_PIN,OUTPUT);
	pinMode(R2_PIN,OUTPUT);
	pinMode(G2_PIN,OUTPUT);
	pinMode(B2_PIN,OUTPUT);
	pinMode(CLK_PIN,OUTPUT);
	pinMode(OE_PIN,OUTPUT);
	pinMode(A_PIN,OUTPUT);
	pinMode(B_PIN,OUTPUT);
	pinMode(C_PIN,OUTPUT);
	pinMode(D_PIN,OUTPUT);
	pinMode(LAT_PIN,OUTPUT);

	pinOutput(A_PIN, 0);
	pinOutput(B_PIN, 0);
	pinOutput(C_PIN, 0);
	pinOutput(D_PIN, 0);
	pinOutput(LAT_PIN, 0);
	pinOutput(OE_PIN, 0);
	pinOutput(CLK_PIN, 1);
	
	clearDisplay();
	startTimer(TC1, 0, TC3_IRQn, 100); //TC1 channel 0, the IRQ for that channel and the desired frequency
}
示例#7
0
void initializeDisplay()
{
	pinMode(13, OUTPUT);
	pinOutput(13, LOW);
	
	pinMode(R1_PIN,OUTPUT);
	pinMode(G1_PIN,OUTPUT);
	pinMode(B1_PIN,OUTPUT);
	pinMode(R2_PIN,OUTPUT);
	pinMode(G2_PIN,OUTPUT);
	pinMode(B2_PIN,OUTPUT);
	pinMode(CLK_PIN,OUTPUT);
	pinMode(OE_PIN,OUTPUT);
	pinMode(A_PIN,OUTPUT);
	pinMode(B_PIN,OUTPUT);
	pinMode(C_PIN,OUTPUT);
	pinMode(LAT_PIN,OUTPUT);

	pinOutput(A_PIN, 0);
	pinOutput(B_PIN, 0);
	pinOutput(C_PIN, 0);
	pinOutput(LAT_PIN, 0);
	pinOutput(OE_PIN, 0);
	pinOutput(CLK_PIN, 1);

	startTimer(TC1, 0, TC3_IRQn, 1000);

	clearDisplay();
}
示例#8
0
void TC3_Handler()
{
	long dummy = REG_TC1_SR0;
	ticks++;
   if (ticks == 1000)
   {
		elapsed_seconds++;
      ticks = 0;
   }
   if (!activated)
      return;
	pinOutput(OE_PIN, 0);
	for (int y = 0; y < 8; y++)
	{
		updateRow(y, display[frame]);
	}
	pinOutput(OE_PIN, 1);
	frame = (frame + 1) % 15;
}
示例#9
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  const uint32_t maxPeriod =
      captureUnitConfig.frequency / pwmUnitConfig.frequency + 1;
  const uint32_t minPeriod =
      captureUnitConfig.frequency / pwmUnitConfig.frequency - 1;

  setupClock();

  const struct Pin led = pinInit(LED_PIN);
  pinOutput(led, false);

  struct GpTimerPwmUnit * const pwmUnit = init(GpTimerPwmUnit,
      &pwmUnitConfig);
  assert(pwmUnit);

  struct Pwm * const pwm = gpTimerPwmCreate(pwmUnit, OUTPUT_PIN);
  assert(pwm);
  pwmSetEdges(pwm, 0, pwmGetResolution(pwm) / 2);

  struct GpTimerCaptureUnit * const captureUnit = init(GpTimerCaptureUnit,
      &captureUnitConfig);
  assert(pwmUnit);

  struct Capture * const capture = gpTimerCaptureCreate(captureUnit, INPUT_PIN,
      PIN_RISING, PIN_PULLDOWN);
  assert(capture);

  uint32_t previousTime = 0;
  bool event = false;

  captureSetCallback(capture, onCaptureEvent, &event);
  captureEnable(capture);
  pwmEnable(pwm);

  while (1)
  {
    while (!event)
      barrier();
    event = false;

    const uint32_t currentTime = captureGetValue(capture);
    const uint32_t period = currentTime - previousTime;

    if (period >= minPeriod && period <= maxPeriod)
      pinReset(led);
    else
      pinSet(led);

    previousTime = currentTime;
  }

  return 0;
}
示例#10
0
RateControlNode::RateControlNode( QSharedPointer<fugio::NodeInterface> pNode )
	: NodeControlBase( pNode ), mHaveInput( false ), mHaveTrigger( false ), mTimeInput( 0 ), mTimeTrigger( 0 )
{
	FUGID( PIN_INPUT_INPUT, "9e154e12-bcd8-4ead-95b1-5a59833bcf4e" );
	FUGID( PIN_OUTPUT_OUTPUT, "261cc653-d7fa-4c34-a08b-3603e8ae71d5" );

	mPinInput   = pinInput( "Input", PIN_INPUT_INPUT );
	mPinTrigger = pinInput( "Trigger", PID_FUGIO_NODE_TRIGGER );

	mPinOutput = pinOutput( "Output", PIN_OUTPUT_OUTPUT );
}
示例#11
0
文件: main.cpp 项目: RCXD/msp430
int main(void)
{
  basic_clock clock = basic_clock();
  spi spi_test = spi(SPI_B0);

  pinOutput(LED_PIN);
  pinOutput(LED_PIN2);
  pinOn(LED_PIN2);

  for (;;) //ever
  {
    for (uint8_t i=0; i<255; i++)
    {
      spi_test.write(i);
    }
    pinToggle(LED_PIN);
    pinToggle(LED_PIN2);
    _delay_s(1);
  }
}
示例#12
0
文件: gppwm.c 项目: stxent/halm
/*----------------------------------------------------------------------------*/
static uint8_t configMatchPin(uint8_t channel, PinNumber key)
{
  const struct PinEntry * const pinEntry = pinFind(gpPwmPins, key, channel);
  assert(pinEntry);

  const struct Pin pin = pinInit(key);

  pinOutput(pin, false);
  pinSetFunction(pin, UNPACK_FUNCTION(pinEntry->value));

  return UNPACK_CHANNEL(pinEntry->value);
}
示例#13
0
文件: main.cpp 项目: RCXD/msp430
int main (void)
{
  // Set up the switch and callback function
  int_sw sw = int_sw(SW_PIN, &toggleLED);
  // Configure the LED_PIN as an output
  pinOutput(LED_PIN);
  pinOn(LED_PIN);
  // Already done by clock library, but enable interrupts again anyway
  _EINT();
  // Enter low power mode 3
  LPM3;
}
示例#14
0
文件: main.cpp 项目: RCXD/msp430
int main(void)
{
  basic_clock clock = basic_clock(DCO_F_1MHz);
  tlc5925 tlc = tlc5925(p1_4);

  pinOutput(LED_PIN);
  pinOutput(LED_PIN2);
  pinOn(LED_PIN2);

  tlc.write((uint16_t)TLC5925_CH01);
  _delay_s(2);
  tlc.write((uint16_t)TLC5925_CH0_15);
  _delay_s(5);

  for (;;) //ever
  {
    tlc.shiftDown(16,TLC5925_CH00);
    pinToggle(LED_PIN);
    pinToggle(LED_PIN2);
    _delay_s(1);
  }
}
示例#15
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  const struct Pin led = pinInit(LED_PIN);
  pinOutput(led, false);

  struct Interface * const flash = init(Flash, 0);
  assert(flash);

  size_t flashSize, pageSize;
  enum Result res;

  pinSet(led);
  if ((res = ifGetParam(flash, IF_SIZE, &flashSize)) == E_OK)
    pinReset(led);
  assert(res == E_OK);

  pinSet(led);
  if ((res = ifGetParam(flash, IF_FLASH_PAGE_SIZE, &pageSize)) == E_OK)
    pinReset(led);
  assert(res == E_OK);

  uint8_t * const buffer = malloc(pageSize);
  for (size_t i = 0; i < pageSize; ++i)
    buffer[i] = i;

  /* Test sector erase */
  const size_t address = findNearestSector();
  assert(address < flashSize);

  pinSet(led);
  if ((res = ifSetParam(flash, IF_FLASH_ERASE_SECTOR, &address)) == E_OK)
    pinReset(led);
  assert(res == E_OK);

  pinSet(led);
  if ((res = program(flash, buffer, pageSize, address)) == E_OK)
    pinReset(led);
  assert(res == E_OK);

  pinSet(led);
  if ((res = verify(flash, buffer, pageSize, address)) == E_OK)
    pinReset(led);
  assert(res == E_OK);

  /* Page erase is not available on some parts */

  while (1);
  return 0;
}
示例#16
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  setupClock();

  const struct Pin led = pinInit(LED_PIN);
  pinOutput(led, false);

  struct Interface * const adc = init(AdcDma, &adcConfig);
  assert(adc);
  ifSetCallback(adc, onConversionCompleted, adc);

  struct Timer * const conversionTimer = init(GpTimer, &timerConfig);
  assert(conversionTimer);
  /*
   * The overflow frequency of the timer should be two times higher
   * than that of the hardware events for ADC.
   */
  timerSetOverflow(conversionTimer, timerConfig.frequency / (ADC_RATE * 2));

  unsigned int iteration = 0;
  size_t count;

  /* Enqueue buffers */
  while (ifGetParam(adc, IF_AVAILABLE, &count) == E_OK && count > 0)
  {
    const size_t index = iteration++ % BUFFER_COUNT;
    ifRead(adc, buffers[index], sizeof(buffers[index]));
  }

  /* Start conversion */
  timerEnable(conversionTimer);

  while (1)
  {
    while (!event)
      barrier();
    event = false;

    pinSet(led);
    while (ifGetParam(adc, IF_AVAILABLE, &count) == E_OK && count > 0)
    {
      const size_t index = iteration++ % BUFFER_COUNT;
      ifRead(adc, buffers[index], sizeof(buffers[index]));
    }
    pinReset(led);
  }

  return 0;
}
示例#17
0
/*----------------------------------------------------------------------------*/
static void deviceInit(struct DeviceDriver *device, struct Interface *interface,
    PinNumber ledNumber, uint16_t address)
{
  device->interface = interface;
  device->state = DEVICE_IDLE;
  device->desiredRate = DEVICE_CLOCK;
  device->localAddress = 0;
  device->deviceAddress = address;
  device->change = false;

  static_assert(MEMORY_ADDRESS_SIZE && MEMORY_ADDRESS_SIZE <= 2,
      "Incorrect address size");
  if (MEMORY_ADDRESS_SIZE == 2)
    device->localAddress = toBigEndian16(device->localAddress);

  device->led = pinInit(ledNumber);
  pinOutput(device->led, false);
}
示例#18
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  setupClock();

  const struct Pin led = pinInit(LED_PIN);
  pinOutput(led, true);

  struct GpTimerPwmUnit * const pwmUnit = init(GpTimerPwmUnit, &pwmUnitConfig);
  assert(pwmUnit);
  struct Pwm * const pwmOutput = gpTimerPwmCreate(pwmUnit, OUTPUT_PIN);
  assert(pwmOutput);
  pwmSetDuration(pwmOutput, pwmGetResolution(pwmOutput) / 2);

  struct Timer * const counter = init(GpTimerCounter, &counterConfig);
  assert(counter);

  struct Timer * const timer = init(GpTimer, &timerConfig);
  assert(timer);
  timerSetOverflow(timer, 1000);

  bool event = false;
  timerSetCallback(timer, onTimerOverflow, &event);

  timerEnable(counter);
  pwmEnable(pwmOutput);
  timerEnable(timer);

  while (1)
  {
    while (!event)
      barrier();
    event = false;

    const uint32_t period = timerGetValue(counter);
    timerSetValue(counter, 0);

    if (period >= 999 && period <= 1001)
      pinReset(led);
    else
      pinSet(led);
  }

  return 0;
}
示例#19
0
// Set the ACLK source and divider
void basic_clock::cfgACLK(aclk_src_t src,
                          clk_div_t  div,
                          xcap_t     cap)
{
  if (src != ACLK_SRC_VLO)
  {
    // Enable XIN and XOUT
    pinInput(XIN_PIN);
    pinSelOn(XIN_PIN);
    pinOutput(XOUT_PIN);
    pinSelOn(XOUT_PIN);
    // Clear the XCAP bits
    off(BCSCTL3, XCAP_3);
  }

  if (src == ACLK_SRC_32kHz)
  {
    // Configure XCAP
    on (BCSCTL3, cap);
  }

  // Clear the source bits
  off(BCSCTL3, LFXT1S_3);
  // Configure the source
  on (BCSCTL3, src);

  // Clear the divider bits
  off(BCSCTL1, (DIV_MAX << DIVA_OFFSET));
  // Configure the divider
  on (BCSCTL1, (div << DIVA_OFFSET));

  // Unless the clock source is VLO, need to let the oscillator stabilize
  if (src != ACLK_SRC_VLO)
  {
    do
    {
      // Clear the XT1 fault flag
      off(BCSCTL3, LFXT1OF);
      // Clear the OFIFG fault flag
      off(IFG1, OFIFG);
    } while (read(BCSCTL3, LFXT1OF));
  }

}
示例#20
0
void updateRow(int y, volatile Color3 frame[32][32])
{
	int temp;
	for (int x = 0; x < 64; x++)
	{
		pinOutput(CLK_PIN, 0);
		if (x < 32)
		{
			PIOB->PIO_CODR = 0x340;
			PIOC->PIO_CODR = 0x7 << 26;
			PIOC->PIO_SODR = frame[x][y] << 26;
			int tmp = 0;
			if (frame[x][y+8]&0x4)
				tmp |= (1 << 8);
			if (frame[x][y+8]&0x2)
				tmp |= (1 << 9);
			if (frame[x][y+8]&0x1)
				tmp |= (1 << 6);
			PIOB->PIO_SODR = tmp;
		}
		else
		{
			PIOB->PIO_CODR = 0x340;
			PIOC->PIO_CODR = 0x7 << 26;
			PIOC->PIO_SODR = frame[x-32][y+16] << 26;
			int tmp = 0;
			if (frame[x-32][y+24]&0x4)
				tmp |= (1 << 8);
			if (frame[x-32][y+24]&0x2)
				tmp |= (1 << 9);
			if (frame[x-32][y+24]&0x1)
				tmp |= (1 << 6);
			PIOB->PIO_SODR = tmp;
		}
      pinOutput(CLK_PIN, 1);
	}
	pinOutput(LAT_PIN, 1);
	pinOutput(LAT_PIN, 0);
	
	// Set the row address
	pinOutput(A_PIN, y&0x1);
	pinOutput(B_PIN, y&0x2);
	pinOutput(C_PIN, y&0x4);
}
示例#21
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  /* Initialize peripherals */
  struct Pin led = pinInit(LED_PIN);
  pinOutput(led, false);

  struct Timer * const timer = init(SysTickTimer, 0);
  assert(timer);
  timerSetOverflow(timer, timerGetFrequency(timer) / 2);
  timerSetCallback(timer, onTimerOverflow, &led);

  /* Initialize Work Queue */
  workQueueInit(WORK_QUEUE_SIZE);

  /* Start event generation and queue handler */
  timerEnable(timer);
  workQueueStart(0);

  return 0;
}
示例#22
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  static const uint32_t address = 0;
  uint8_t buffer[384];

  for (size_t i = 0; i < sizeof(buffer); ++i)
    buffer[i] = i;

  const struct Pin led = pinInit(LED_PIN);
  pinOutput(led, false);

  struct Interface * const eeprom = init(Eeprom, 0);
  assert(eeprom);

  uint32_t size;
  enum Result res;

  pinSet(led);
  if ((res = ifGetParam(eeprom, IF_SIZE, &size)) == E_OK)
    pinReset(led);
  assert(res == E_OK);

  assert(address < size);

  pinSet(led);
  if ((res = program(eeprom, buffer, sizeof(buffer), address)) == E_OK)
    pinReset(led);
  assert(res == E_OK);

  pinSet(led);
  if ((res = verify(eeprom, buffer, sizeof(buffer), address)) == E_OK)
    pinReset(led);
  assert(res == E_OK);

  while (1);
  return 0;
}
示例#23
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  const struct Pin led = pinInit(LED_PIN);
  pinOutput(led, true);

  struct Timer * const timer = init(GpTimer, &timerConfig);
  assert(timer);
  timerSetOverflow(timer, 500);

  bool event = false;
  timerSetCallback(timer, onTimerOverflow, &event);
  timerEnable(timer);

  while (1)
  {
    while (!event)
      barrier();
    event = false;

    pinToggle(led);
  }

  return 0;
}
示例#24
0
DecimateNode::DecimateNode( QSharedPointer<fugio::NodeInterface> pNode )
	: NodeControlBase( pNode )
{
	FUGID( PIN_INPUT_COUNT, "c6b773cb-791e-431e-a265-7ec3cdd6cc46" );
	FUGID( PIN_INPUT_RESET, "CB7333A0-4D5F-441C-80FA-D6220132C6BC" );
	FUGID( PIN_INPUT_VALUE, "9e154e12-bcd8-4ead-95b1-5a59833bcf4e" );
	FUGID( PIN_OUTPUT_VALUE, "1b5e9ce8-acb9-478d-b84b-9288ab3c42f5" );

	mPinInputCount = pinInput( tr( "Count" ), PIN_INPUT_COUNT );

	mPinInputReset = pinInput( tr( "Reset" ), PIN_INPUT_RESET );

	mPinInput = pinInput( tr( "Input" ), PIN_INPUT_VALUE );

	mPinOutput = pinOutput( "Output", PIN_OUTPUT_VALUE );

	mPinInput->setAutoRename( true );

	mNode->pairPins( mPinInput, mPinOutput );

	connect( mNode->qobject(), SIGNAL(pinLinked(QSharedPointer<fugio::PinInterface>,QSharedPointer<fugio::PinInterface>)), this, SLOT(pinLinked(QSharedPointer<fugio::PinInterface>,QSharedPointer<fugio::PinInterface>)) );

	connect( mNode->qobject(), SIGNAL(pinUnlinked(QSharedPointer<fugio::PinInterface>,QSharedPointer<fugio::PinInterface>)), this, SLOT(pinUnlinked(QSharedPointer<fugio::PinInterface>,QSharedPointer<fugio::PinInterface>)) );
}
示例#25
0
InstanceBufferNode::InstanceBufferNode( QSharedPointer<fugio::NodeInterface> pNode )
	: NodeControlBase( pNode )
{
	mPinInput = pinInput( "Input", next_uuid() );
	mPinOutput = pinOutput( "Output", next_uuid() );
}