#ifndef NMAP_GPIO_SCREEN
#define NMAP_GPIO_SCREEN

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <fcntl.h>
#include <sys/mman.h>

// Datasheet doc: "Atmel-11121-32-bit-Cortex-A5-Microcontroller-SAMA5D3_Datasheet.pdf"

// Needed for mmap
// Addresses from p.30 of datasheet
#define SMC_BASE		    0xffffc000
#define GPIOA_BASE_ADDR     0xfffff200
#define GPIOA_END_ADDR      0xfffff400

#define PIOA_MEM_SIZE       (GPIOA_END_ADDR - SMC_BASE)
#define GPIOA_OFFSET	    (GPIOA_BASE_ADDR - SMC_BASE)

// Addresses from p.289 of datasheet
#define PIO_PER             0x0    // PIO Enable Register
#define PIO_PDR             0x4    // PIO Disable Register
#define PIO_PSR             0x8    // PIO Status Register

#define PIO_OER             0x10   // Output Enable Register
#define PIO_ODR             0x14   // Output Disable Register
#define PIO_OSR             0x18   // Output Status Register

#define PIO_SODR            0x30   // Set Output Data Register
#define PIO_CODR            0x34   // Clear Output Data Register
#define PIO_ODSR            0x38   // Output Data Status Register

#define COMMAND_PIN 20
#define BACKLIGHT_PIN 22


void init_pin_screen(int *fd,void **gpio_base_addr);
void set_backlight(bool state, void *gpio_base_addr);
void free_pin_screen(int fd, void *gpio_base_addr);
void set_command(bool state, void *gpio_base_addr);

#endif
