Skip to content

Commit

Permalink
First commit of the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhijith Sriram committed Oct 1, 2024
1 parent 67e0c1f commit 74ddf21
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
vsCode_workspace.code-workspace
out/
Binary file not shown.
Binary file added docs/Arduino uno R3 datasheet.pdf
Binary file not shown.
Binary file not shown.
Binary file added docs/avrdude.pdf
Binary file not shown.
16 changes: 16 additions & 0 deletions src/appl/blinkLed.c
Original file line number Diff line number Diff line change
@@ -0,0 1,16 @@
#include "utils.h"
#include "pin.h"

void main()
{
/* Configure pin PB5 to output*/
Configure_pinPort(PORTB, (uint8_t)PINB5, OUTPUT);

/* The main loop for the application */
while(1)
{
Write_pin(PORTB, (uint8_t)PINB5, PIN_HIGH);
Delay();
Write_pin(PORTB, (uint8_t)PINB5, PIN_LOW);
}
}
3 changes: 3 additions & 0 deletions src/lib/data_types.h
Original file line number Diff line number Diff line change
@@ -0,0 1,3 @@
#include <stdint.h>

typedef uint8_t bool_t;
9 changes: 9 additions & 0 deletions src/lib/memory_cal.h
Original file line number Diff line number Diff line change
@@ -0,0 1,9 @@
/*
* File containing the address for registers and other related stuff
*
*/
#include <stdint.h>

#define GPIOB (0x23U)
#define GPIOC (0x26U)
#define GPIOD (0x29U)
42 changes: 42 additions & 0 deletions src/lib/pin.c
Original file line number Diff line number Diff line change
@@ -0,0 1,42 @@
#include <stdint.h>
#include "memory_cal.h"
#include "pin.h"

/*
* Function to configure ports for read or write
*
* INPUT
* @param gpio *port - pointer to a general purpose IO register
use macros PORTB/PORTC/PORTD
* @param uint8_t pin - the pin number from the enum PINB/PINC/PIND
typecast to uint8_t
* @param PIN_CONFIG pin_config - Pin configuration INPUT/OUTPUT
*
* OUTPUT
* None
*/
void Configure_pinPort(gpio *port, uint8_t pin, PIN_CONFIG pin_config)
{
port->ddr |= (((uint8_t) pin_config) << pin);
if(pin_config == INPUT)
{
/* This is to activate the pull-up resistor */
port->port |= (((uint8_t) 1) << pin);
}
else
{
/* do nothing */
}
}

PIN_VALUE Read_pin(gpio* port, uint8_t pin)
{
uint8_t mask = ((uint8_t) 1 << pin);
uint8_t pin_value = (port->pin & mask) >> pin;
return (PIN_VALUE) pin_value;
}

void Write_pin(gpio* port, uint8_t pin, PIN_VALUE value)
{
port->pin |= (((uint8_t) value) << pin);
}
68 changes: 68 additions & 0 deletions src/lib/pin.h
Original file line number Diff line number Diff line change
@@ -0,0 1,68 @@
#include <stdint.h>
#include "memory_cal.h"

/* Data types */
typedef struct
{
volatile uint8_t pin;
volatile uint8_t ddr;
volatile uint8_t port;
}gpio;

typedef enum
{
PINB0 = 0,
PINB1,
PINB2,
PINB3,
PINB4,
PINB5,
PINB6,
PINB7
} PINB;

typedef enum
{
PINC0 = 0,
PINC1,
PINC2,
PINC3,
PINC4,
PINC5,
PINC6
} PINC;

typedef enum
{
PIND0 = 0,
PIND1,
PIND2,
PIND3,
PIND4,
PIND5,
PIND6,
PIND7
} PIND;

typedef enum
{
INPUT = 0,
OUTPUT
}PIN_CONFIG;

typedef enum
{
PIN_LOW = 0,
PIN_HIGH
}PIN_VALUE;

/* Macros */
#define PORTB (volatile gpio*) GPIOB
#define PORTC (volatile gpio*) GPIOC
#define PORTD (volatile gpio*) GPIOD

/* Function prototypes */

void Configure_pinPort(gpio *port, uint8_t pin, PIN_CONFIG pin_config);
PIN_VALUE Read_pin(gpio* port, uint8_t pin);
void Write_pin(gpio* port, uint8_t pin, PIN_VALUE value);
10 changes: 10 additions & 0 deletions src/lib/utils.c
Original file line number Diff line number Diff line change
@@ -0,0 1,10 @@
#include "utils.h"

void Delay(void)
{
volatile uint8_t temp;
for (uint32_t indx=(uint32_t)0; indx<DELAY_INDEX; indx )
{
temp=((uint8_t)0);
}
}
4 changes: 4 additions & 0 deletions src/lib/utils.h
Original file line number Diff line number Diff line change
@@ -0,0 1,4 @@
#include <stdint.h>

#define DELAY_INDEX (uint32_t) 1000000
void Delay(void);

0 comments on commit 74ddf21

Please sign in to comment.