Exemplo n.º 1
0
Arquivo: lcd.cpp Projeto: bratkov/tmos
WEAK void backlight_thread(LCD_MODULE *lcd)
{
    ALLOCATE_SIGNAL(SIG_BACKLIGHT_TASK);

    PIO_CfgOutput1(lcd->pins[BKLT_PIN_INDX]);
    while(1)
    {
     	PIO_SetOutput(lcd->pins[BKLT_PIN_INDX]);
     	if(tsk_wait_signal(SIG_BACKLIGHT_TASK, backlight_time ))
     		continue;
     	if(backlight_time)
     	{
			// reduce the current consumption to 5%
			int t = 20;
			while(!tsk_test_signal(SIG_BACKLIGHT_TASK))
			{
				PIO_SetOutput(lcd->pins[BKLT_PIN_INDX]);
				tsk_sleep(t);
				PIO_ClrOutput(lcd->pins[BKLT_PIN_INDX]);
				tsk_sleep(20 - t--);
				if(!t)
					t=1;
			}
     	}
       	tsk_get_signal(SIG_BACKLIGHT_TASK);
    }
}
Exemplo n.º 2
0
/**
 * \brief Configures a list of Pin instances, each of which can either hold a single
 * pin or a group of pins, depending on the mask value; all pins are configured
 * by this function. The size of the array must also be provided and is easily
 * computed using PIO_LISTSIZE whenever its length is not known in advance.
 *
 * \param list  Pointer to a list of Pin instances.
 * \param size  Size of the Pin list (calculated using PIO_LISTSIZE).
 *
 * \return 1 if the pins have been configured properly; otherwise 0.
 */
uint8_t PIO_Configure( const Pin *list, uint32_t size )
{
    /* Configure pins */
    while ( size > 0 )
    {
        switch ( list->type )
        {

            case PIO_PERIPH_A:
                PIO_SetPeripheralA(list->pio,
                        list->mask,
                        (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;

            case PIO_PERIPH_B:
                PIO_SetPeripheralB(list->pio,
                        list->mask,
                        (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;

            case PIO_PERIPH_C:
                PIO_SetPeripheralC(list->pio,
                        list->mask,
                        (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;

            case PIO_PERIPH_D:
                PIO_SetPeripheralD(list->pio,
                        list->mask,
                        (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;
            case PIO_INPUT:
#ifndef __FPGA
                PMC_EnablePeripheral(list->id);
#endif
                PIO_SetInput(list->pio,
                        list->mask,
                        list->attribute);
                break;

            case PIO_OUTPUT_0:
            case PIO_OUTPUT_1:
                PIO_SetOutput(list->pio,
                        list->mask,
                        (list->type == PIO_OUTPUT_1),
                        (list->attribute & PIO_OPENDRAIN) ? 1 : 0,
                        (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;

            default: return 0;
        }

        list++;
        size--;
    }

    return 1;
}
Exemplo n.º 3
0
//------------------------------------------------------------------------------
/// Configures a list of Pin instances, each of which can either hold a single
/// pin or a group of pins, depending on the mask value; all pins are configured
/// by this function. The size of the array must also be provided and is easily
/// computed using PIO_LISTSIZE whenever its length is not known in advance.
/// \param list  Pointer to a list of Pin instances.
/// \param size  Size of the Pin list (calculated using PIO_LISTSIZE).
/// \return 1 if the pins have been configured properly; otherwise 0.
//------------------------------------------------------------------------------
unsigned char PIO_Configure(const Pin *list, unsigned int size)
{
    // Configure pins
    while (size > 0) {
    
        switch (list->type) {
    
            case PIO_PERIPH_A:
                PIO_SetPeripheralA(list->pio,
                                   list->mask,
                                   (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;
    
            case PIO_PERIPH_B:
                PIO_SetPeripheralB(list->pio,
                                   list->mask,
                                   (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;
    
            case PIO_INPUT:
                AT91C_BASE_PMC->PMC_PCER = 1 << list->id;
                PIO_SetInput(list->pio,
                             list->mask,
                             (list->attribute & PIO_PULLUP) ? 1 : 0,
                             (list->attribute & PIO_DEGLITCH)? 1 : 0);

                #if defined(AT91C_PIOA_IFDGSR) //PIO3 with Glitch or Debouncing selection
                //if glitch input filter enabled, set it
                if(list->attribute & PIO_DEGLITCH)//Glitch input filter enabled
                    PIO_SetFilter(list->pio,
                        list->inFilter.filterSel,
                        list->inFilter.clkDivider);
                #endif
                break;
    
            case PIO_OUTPUT_0:
            case PIO_OUTPUT_1:
                PIO_SetOutput(list->pio,
                              list->mask,
                              (list->type == PIO_OUTPUT_1),
                              (list->attribute & PIO_OPENDRAIN) ? 1 : 0,
                              (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;
    
            default: return 0;
        }

        list++;
        size--;
    }

    return 1;
}
Exemplo n.º 4
0
Arquivo: pio.c Projeto: ARMinARM/elua
//------------------------------------------------------------------------------
//         Exported functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// Configures a list of Pin instances, which can either hold a single pin or a 
/// group of pins, depending on the mask value; all pins are configured by this 
/// function.
/// Returns 1 if the configuration has been performed successfully; otherwise 0.
/// \param list  Pointer to a list of Pin instances.
/// \param size  Size of the Pin list (see <PIO_LISTSIZE>).
//------------------------------------------------------------------------------
unsigned char PIO_Configure(const Pin *list, unsigned int size)
{
    // Configure pins
    while (size > 0) {
    
        switch (list->type) {
    
            case PIO_PERIPH_A:
                PIO_SetPeripheralA(list->pio,
                                   list->mask,
                                   (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;
    
            case PIO_PERIPH_B:
                PIO_SetPeripheralB(list->pio,
                                   list->mask,
                                   (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;
    
            case PIO_INPUT:
                AT91C_BASE_PMC->PMC_PCER = 1 << list->id;
                PIO_SetInput(list->pio,
                             list->mask,
                             (list->attribute & PIO_PULLUP) ? 1 : 0,
                             (list->attribute & PIO_DEGLITCH)? 1 : 0);
                break;
    
            case PIO_OUTPUT_0:
            case PIO_OUTPUT_1:
                PIO_SetOutput(list->pio,
                              list->mask,
                              (list->type == PIO_OUTPUT_1),
                              (list->attribute & PIO_OPENDRAIN) ? 1 : 0,
                              (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;
    
            default: return 0;
        }

        list++;
        size--;
    }

    return 1;
}
Exemplo n.º 5
0
Arquivo: lcd.cpp Projeto: bratkov/tmos
void LCD_MODULE::lcd_init(GUI_CB splash)
{
#if GUI_DISPLAYS > 1
	if(display == 1)
#endif
	{
		usr_task_init_static(&backlight_task_desc, false);
		backlight_task.sp->r0.as_voidptr = this;
		usr_task_schedule(backlight_task_desc.tsk);
	}

	// LCD Reset
	PIO_CfgOutput0(pins[RST_PIN_INDX]);
	tsk_sleep(20);
	PIO_SetOutput(pins[RST_PIN_INDX]);
	tsk_sleep(20);

    //LCD Handle initialization (LCD attached to SPI)
    lcd_hnd->tsk_safe_open(lcd_hnd->drv_index, lcd_hnd->mode.as_voidptr);
    lcd_reset();
}
Exemplo n.º 6
0
extern void digitalWrite( uint32_t ulPin, uint32_t ulVal )
{
  /* Handle */
	if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
  {
    return ;
  }

  if ((g_pinStatus[ulPin] & 0xF) == PIN_STATUS_PWM) {
    pinMode(ulPin, OUTPUT);
  }

  g_pinStatus[ulPin] = (g_pinStatus[ulPin] & 0x0F) | (ulVal << 4) ;

  if ( PIO_GetOutputDataStatus( g_APinDescription[ulPin].pPort, g_APinDescription[ulPin].ulPin ) == 0 )
  {
    PIO_PullUp( g_APinDescription[ulPin].pPort, g_APinDescription[ulPin].ulPin, ulVal ) ;
  }
  else
  {
    PIO_SetOutput( g_APinDescription[ulPin].pPort, g_APinDescription[ulPin].ulPin, ulVal, 0, PIO_PULLUP ) ;
  }
}
Exemplo n.º 7
0
extern void digitalWrite( uint32_t ulPin, uint32_t ulVal )
{
  /* Handle */
	if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
  {
    return ;
  }

    /* Added by Y.Ishioka */
    if( ulPin == 13 ) {
        led_set( ulVal & 0x01 ) ;
        return ;
    }


  if ( PIO_GetOutputDataStatus( g_APinDescription[ulPin].pPort, g_APinDescription[ulPin].ulPin ) == 0 )
  {
    PIO_PullUp( g_APinDescription[ulPin].pPort, g_APinDescription[ulPin].ulPin, ulVal ) ;
  }
  else
  {
    PIO_SetOutput( g_APinDescription[ulPin].pPort, g_APinDescription[ulPin].ulPin, ulVal, 0, PIO_PULLUP ) ;
  }
}
Exemplo n.º 8
0
/**
 *
 * \return 1 if the pins have been configured properly; otherwise 0.
 */
extern uint32_t PIO_Configure( Pio* pPio, const EPioType dwType, const uint32_t dwMask, const uint32_t dwAttribute )
{
    /* Configure pins */
    switch ( dwType )
    {
        case PIO_PERIPH_A :
        case PIO_PERIPH_B :
#if (defined _SAM3S_) || (defined _SAM3S8_) || (defined _SAM3N_)
        case PIO_PERIPH_C :
        case PIO_PERIPH_D :
#endif /* (defined _SAM3S_) || (defined _SAM3S8_) || (defined _SAM3N_) */
            /* Put the pin under control of peripheral */
            PIO_SetPeripheral( pPio, dwType, dwMask ) ;
            /* Disable interrupts on the pin(s) */
            PIO_DisableInterrupt( pPio, dwMask ) ;
            /* Enable Pullup */
            PIO_PullUp( pPio, dwMask, (dwAttribute & PIO_PULLUP) ) ;
        break;

        case PIO_INPUT :
            PIO_SetInput( pPio, dwMask, dwAttribute ) ;
        break;

        case PIO_OUTPUT_0 :
        case PIO_OUTPUT_1 :
            PIO_SetOutput( pPio, dwMask, (dwType == PIO_OUTPUT_1),
                          (dwAttribute & PIO_OPENDRAIN) ? 1 : 0,
                          (dwAttribute & PIO_PULLUP) ? 1 : 0);
        break ;

        default :
        return 0 ;
    }

    return 1 ;
}
Exemplo n.º 9
0
void isr_SerilaDriver(UART_DRIVER_INFO* drv_info )
{
	UART_Type * Uart = drv_info->hw_base;
	UART_DRIVER_DATA * drv_data = drv_info->drv_data;
	HANDLE hnd;

	unsigned int Status = Uart->UARTIntStatus(true);
	Uart->UARTIntClear(Status);

	if( Status & UART_INT_TX)
	{
		if((hnd=drv_data->hnd_snd))
		{
			while(Uart->UARTSpaceAvail())
			{
				if(!hnd->len)
				{
					drv_data->hnd_snd = hnd->next;
					usr_HND_SET_STATUS(hnd, RES_SIG_OK);
					if(!(hnd=drv_data->hnd_snd))
					{
						STOP_TX(Uart);
						break;
					}
				}
				hnd->len--;
				Uart->DR = *hnd->src.as_charptr++;
			}
			if(hnd)
			{
				Uart->UARTTxIntModeSet(UART_TXINT_MODE_FIFO);
			}
		}
		else
		{
			STOP_TX(Uart);
		}
	}

	//check the receiver
    if(Status&(UART_INT_RT|UART_INT_RX))
    {
    	while(Uart->UARTCharsAvail())
    	{
    		drv_data->rx_remaining--;
    		*drv_data->rx_wrptr++ = Uart->DR;
    		if(drv_data->hnd_rcv && !drv_data->hnd_rcv->mode0)
    			drv_data->hnd_rcv->mode0 = 1;
    		if(!drv_data->rx_remaining )
    		{
    	    	if( (hnd=drv_data->hnd_rcv) )
    				STOP_RX_HND(Uart, drv_info, hnd);
    	      	else
    				START_RX_BUF(Uart, drv_info, drv_data);
    		}
#ifdef HW_VER_10
    		else
    		{
    			if(drv_data->mode.hw_flow && drv_info->info.drv_index != UART1_IRQn)
					if((!drv_data->hnd_rcv) && (drv_data->rx_remaining < (RX_BUF_SIZE/4)))
					{
						if(drv_info->uart_pins[RTS_PIN])
							PIO_SetOutput(drv_info->uart_pins[RTS_PIN]);
					}
    		}
#endif
    	}
    	if( (Status&UART_INT_RT) && drv_data->mode.rx_tout )
    	{
	    	if( (hnd=drv_data->hnd_rcv) )
	    	{
	    		if(drv_data->rx_remaining != hnd->len)
	    			STOP_RX_HND(Uart, drv_info, hnd);
	    	}
    	}
	}
}
Exemplo n.º 10
0
/**
 * \brief Configures a list of Pin instances, each of which can either hold a single
 * pin or a group of pins, depending on the mask value; all pins are configured
 * by this function. The size of the array must also be provided and is easily
 * computed using PIO_LISTSIZE whenever its length is not known in advance.
 *
 * \param list  Pointer to a list of Pin instances.
 * \param size  Size of the Pin list (calculated using PIO_LISTSIZE).
 *
 * \return 1 if the pins have been configured properly; otherwise 0.
 */
extern uint32_t PIO_PinConfigure( const Pin* pPins, uint32_t dwSize )
{
    uint32_t dwOptions=0 ;

    /* Configure pins */
    while ( dwSize > 0 )
    {
        switch ( pPins->type )
        {
            case PIO_PERIPH_A :
                if ( pPins->attribute & PIO_PULLUP )
                {
                    dwOptions=PIO_PULLUP ;
                }

                PIO_SetPeripheralA( pPins->pio, pPins->mask, dwOptions ) ;
            break ;

            case PIO_PERIPH_B :
                if ( pPins->attribute & PIO_PULLUP )
                {
                    dwOptions=PIO_PULLUP ;
                }

                PIO_SetPeripheralB( pPins->pio, pPins->mask, dwOptions ) ;
            break ;

            case PIO_INPUT :
                PMC_EnablePeripheral( pPins->id ) ;
                PIO_SetInput( pPins->pio, pPins->mask, pPins->attribute ) ;
            break ;

            case PIO_OUTPUT_0 :
            case PIO_OUTPUT_1 :
                if ( pPins->type == PIO_OUTPUT_1 )
                {
                    dwOptions|=PIO_OUTPUT_HIGH ;
                }

                if ( pPins->attribute & PIO_OPENDRAIN )
                {
                    dwOptions|=PIO_OPENDRAIN ;
                }

                if ( pPins->attribute & PIO_PULLUP )
                {
                    dwOptions|=PIO_PULLUP ;
                }

                PIO_SetOutput( pPins->pio, pPins->mask, dwOptions ) ;
            break ;

            default :
                return 0 ;
        }

        pPins++ ;
        dwSize-- ;
    }

    return 1 ;
}