Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssd1306 device driver example #37

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

DevyatovAndrey
Copy link

@DevyatovAndrey DevyatovAndrey commented Nov 20, 2017

This adds step by step example of writing kernel device driver for OLED LCD display based on ssd1306 controller.

@DevyatovAndrey DevyatovAndrey changed the title Andrii.deviatov ssd1306 device driver example Nov 20, 2017
Copy link
Collaborator

@AleksandrBulyshchenko AleksandrBulyshchenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DevyatovAndrey,
Thank you for sharing the driver.

But could you rebase the branch onto this repo tree?
Because currently it's impossible to diff separate commits via github.

And also if possible -please fix checkpatch issues (at least for the ssd1306, but it make sense for userapp_analog_clock as well):

${BBB_KERNEL}/scripts/checkpatch.pl --file ${TRAINING_REPO}/ssd1306/*.[ch] --terse

ssd1306/Makefile Outdated
obj-m := ssd1306.o

KDIR ?= ${HOME}/BBB/bb_kernel/
#KDIR ?= ~/BBB/KERNEL/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid hardcodding any local path.
And unify expected env. vars with existent mpu6050 driver (see its makefile)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,41 @@
#!/bin/bash -e

export CROSS_COMPILE=${HOME}/BBB/gcc-linaro-5.3.1-2016.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hardcodded export will override anything set in user's environment.
Please avoid committing your paths.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,415 @@
/*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use the same baseline version of am335x-bone-common.dtsi as mpu6050 uses? (see ee49cc6)


clean:
rm fb_user

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makefile has very odd view.
Does it work at all?

I believe you meant something like the following

CROSS_COMPILE ?= arm-linux-gnueabihf-
CC = $(CROSS_COMPILE)gcc
CFLAGS = -Wall

.PHONY: all clean

all: analog_clock

analog_clock: analog_clock.c
	$(CC) $(CFLAGS) $^ -o $@

clean:
	rm analog_clock

@@ -0,0 +1,11 @@
#!/bin/bash -e

export CROSS_COMPILE=${HOME}/BBB/gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux/bin/arm-linux-gnueabihf-
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid using hardcoded absolute paths - use just filename and add its location to $PATH

@@ -0,0 +1,11 @@
#!/bin/bash -e
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you have shell script and makefile same time.
I believe something one is enough (preferably Makefile if you don't have to use some complex shell scripting)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just to have an unified way to build and deploy this application

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So which one is correct?
Now they use different options.

  • Either make should be called from the shell script and everything have to be defined in the makefile (as it done for ssd1306);
  • or one of them should be removed to avoid confusion.

@DevyatovAndrey
Copy link
Author

@AleksandrBulyshchenko,

  • The branch is rebased onto this repo tree.
  • Fixed checkpatch issues
  • Removed unnesessary export of enviroment variabless

Copy link
Collaborator

@AleksandrBulyshchenko AleksandrBulyshchenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DevyatovAndrey,
Thank you for the fixes.

Here some more comments:

  • It's better to remove mistakenly added build artefacts right in that commit (8e7c145).
  • What about unifying am335x-bone-common.dtsi base with mpu6050? (will require editing of f243df6)
  • If possible, please provide more descriptive commit messages.

u8 type;
u8 data[LCD_WIDTH * LCD_HEIGHT / 8];

u8 data[LCD_WIDTH * LCD_HEIGHT / 8];
} ssd1306_data_array;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ssd1306.c:90: WARNING: do not add new typedefs

ret = i2c_master_send(drv_client, (u8 *) &dataArray,
sizeof(ssd1306_data_array));

if (unlikely(ret < 0)) {
printk(KERN_ERR "i2c_master_send() has returned ERROR %d\n", ret);
return ret;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use pr_err()

envsetup.sh Outdated
@@ -4,15 +4,15 @@ export CROSS_COMPILE=${HOME}/BBB/gcc-linaro-5.3.1-2016.05-x86_64_arm-linux-gnuea

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this envsetup.sh should be published at all.
It will be different for everybody (and don't have to be at all)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to set up enviroment variables needed for these examples if there is no "envsetup.sh"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea of using environment variables - is exactly to allow to use own environment, which is different for every user (otherwise they should be defined in build scripts instead of passing from environment).
So storing environment settings in VCS doesn't make much sense, because they either will be changed by users and will create a noise in git status or won't be used.

@@ -0,0 +1,11 @@
#!/bin/bash -e
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So which one is correct?
Now they use different options.

  • Either make should be called from the shell script and everything have to be defined in the makefile (as it done for ssd1306);
  • or one of them should be removed to avoid confusion.

echo "configure kernel"
make ARCH=arm config
;;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant space line

PWD := $(shell pwd)

default:
$(MAKE) ARCH=arm -C $(KDIR) M=$(PWD) modules
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please unify indentation - use single tab

@DevyatovAndrey
Copy link
Author

I've updated this PR:

  • removed mistakenly added build artefacts
  • unified am335x-bone-common.dtsi base with mpu6050

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants