Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

More int type fixes and tests for drivers #80

Merged
merged 6 commits into from
Jul 8, 2014

Conversation

errordeveloper
Copy link
Member

Just pulled in nightly and got a whole bunch of errors like this:

error: cannot determine a type for this expression: cannot determine the type of this integer; add a suffix to specify the type explicitly

Not sure, may be this just a follow-up on rust-lang/rust#6023?

@farcaller
Copy link
Member

Not sure how that is "making the language more simple", but whatever. Just one comment above

@@ -121,7 +121,7 @@ impl<'a, S: SPI, T: Timer, P: GPIO> C12332<'a, S, T, P> {
let index = x + (y/8) * 128;
if color == 0 {
self.videobuf[index as uint].set(
self.videobuf[index as uint].get() & !(1 << (y%8) as uint) as u8);
self.videobuf[index as uint].get() & !(1i32 << (y%8i32) as uint) as u8);
Copy link
Member

Choose a reason for hiding this comment

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

Why is this signed int? it's getting downcasted to u8, so using u8 should be fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right!

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, that gives me another error:

/Users/ilya/Code/Work/rust/zinc/src/drivers/lcd/c12332.rs:124:58: 124:61 error: mismatched types: expected `i32` but found `i8` (expected i32 but found i8)
/Users/ilya/Code/Work/rust/zinc/src/drivers/lcd/c12332.rs:124         self.videobuf[index as uint].get() & !(1i8 << (y%8i8) as uint) as u8);

Copy link
Member

Choose a reason for hiding this comment

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

Ah. so, y being i32 is kind of a bug, as you cannot really address any pixel < 0. If you have some time to work on this, can you please update function definition to read pub fn set_pixel(&self, x: u32, y: u32, color: u16) ? Then the addressing should be something along the lines of (1u8 << (y % 8u32) as uint) as u8

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, that's what I was thinking, but wasn't sure...

Copy link
Member Author

Choose a reason for hiding this comment

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

And is this a bug as well?

src/drivers/lcd/mod.rs:  fn pixel(&self, x: i32, y: i32, color: u16);

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that one as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, will fix it.

@errordeveloper
Copy link
Member Author

I won't be surprised it will go away. May be we need refactor those kind of expressions somehow?

@farcaller
Copy link
Member

Most of that is bits manipulation. It would be nice to have some macro to do that in a better (and more safe way).

@errordeveloper
Copy link
Member Author

It certainly needs some nice macros.

@errordeveloper
Copy link
Member Author

Looks a little cleaner now 😄

@farcaller
Copy link
Member

A bit mode cleaning please: https://travis-ci.org/errordeveloper/zinc/jobs/28985715#L103

@errordeveloper
Copy link
Member Author

Yeah... The warning, wasn't quite sure what's the fix...
On 2 Jul 2014 18:32, "Vladimir Pouzanov" [email protected] wrote:

A bit mode cleaning please:
https://travis-ci.org/errordeveloper/zinc/jobs/28985715#L103

Reply to this email directly or view it on GitHub
#80 (comment).

@farcaller
Copy link
Member

In c12332 — it's safe to remove the check for < 0.

In lcd/mod.rs — you actually broke the algorithm, all the variables other than x0/y0 can be less than zero.

@errordeveloper
Copy link
Member Author

So 35440a6 fixes C12332. And for the broken algorithm I'm thinking of fixing it with if di < 0i as u32, which seem about right to me.

@farcaller
Copy link
Member

No, di must be i32, as di = dy_x2 - dx might be less than zero.

@errordeveloper
Copy link
Member Author

Well, if they are unsigned, they will never be less then zero, it will
simply overflow, isn't it?
On 2 Jul 2014 20:31, "Vladimir Pouzanov" [email protected] wrote:

No, di must be i32, as di = dy_x2 - dx might be less than zero.

Reply to this email directly or view it on GitHub
#80 (comment).

@errordeveloper
Copy link
Member Author

So in terms of geometry, what does the zero represent here? Is it more like
the centre of a line (-∞:0:+∞) or beginning of a line [0:+∞)?

@errordeveloper
Copy link
Member Author

@farcaller I'm thinking that we should have test for this, generate a bitmap and compare it to a static bitmap, what do you think?

@farcaller
Copy link
Member

Ok. I can run the test on actual hw this weekend, but you can go on and make an unit test.

@errordeveloper
Copy link
Member Author

Yeah, I'd love to! Might need a little help, if you don't mind... Will ping
you tomorrow ;)
On 2 Jul 2014 21:57, "Vladimir Pouzanov" [email protected] wrote:

Ok. I can run the test on actual hw this weekend, but you can go on and
make an unit test.

Reply to this email directly or view it on GitHub
#80 (comment).

@errordeveloper
Copy link
Member Author

Will re-open when unit tests are done.

@errordeveloper errordeveloper reopened this Jul 6, 2014
@errordeveloper
Copy link
Member Author

@farcaller this is on top of #89.

@farcaller farcaller changed the title More int type fixes More int type fixes and tests for drivers Jul 6, 2014
source: 'main.rs'.in_source,
deps: [:core_crate],
produce: 'zinc_test'.in_build,
recompile_on: [:triple, :platform, :features],
Copy link
Member

Choose a reason for hiding this comment

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

Do not recompile on :triple, host triple isn't going to change.

fn should_fill_and_clear() {
let io = TestLCD::new();
io.set_fill(128);
io.for_each(|_, x| {
Copy link
Member

Choose a reason for hiding this comment

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

io.for_each(|_, x| assert!(x == 128));

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, so generally make things like this to one line unless it's too long?

Copy link
Member Author

Choose a reason for hiding this comment

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

the syntax is actually nicer then Ruby!

Copy link
Member

Choose a reason for hiding this comment

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

Right. you don't need curly braces if the statement is simple, if it spans a few lines you still add them for readability (although it's syntactically correct to drop them).

@farcaller
Copy link
Member

I think you can do with a much smaller buffer, like 5x5 pixels, this way you can make a helper test case macro that makes a call and verifies it by the "picture". Bonus points if you define the template with something like

let match = "
.....
.XXXX
.X..X
.XXXX
....."

@errordeveloper
Copy link
Member Author

@farcaller regarding the buffer, I though might as well print a letter using putc, so 16x16 seemed like good enough...

@errordeveloper errordeveloper mentioned this pull request Jul 7, 2014
@errordeveloper
Copy link
Member Author

Travis might have hit a rustc bug, but I'd rather rebase this on #92 first. I'm also thinking to squash this down to a couple of commits. From 15 to 3 or 5, perhaps...

@errordeveloper
Copy link
Member Author

Does anyone else want to review this or we can merge?

@farcaller
Copy link
Member

Please remove this test: test dummy_test ... ok

@errordeveloper
Copy link
Member Author

Removed. Should I squash or it's okay?


io.line(0, 0, 15, 15, 1);

// TODO: investigate why this hangs the test run in `__psynch_cvwait()`
Copy link
Member

Choose a reason for hiding this comment

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

Please 'own' the todo: // TODO(errordeveloper): ...

@farcaller
Copy link
Member

Yes, you can squash it a bit (reasonably).

- pixel coordinates are always unsigned
- use `for ... in range(...)` instead of `while ...`
fn line(&self, x0_b: u32, y0_b: u32, x1: u32, y1: u32, color: u16) {
let mut x0: u32 = x0_b;
let mut y0: u32 = y0_b;
let mut dx: u32;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these dx want to be i32?

Copy link
Contributor

Choose a reason for hiding this comment

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

dx, dy, dx_sym and dy_sym at the minimum should be signed. This should fix your hanging test.

Copy link
Contributor

Choose a reason for hiding this comment

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

And it might be nicer if you get rid of the 'mut' and just rebind with another let statement. di, x0 and y0 should be mut.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, those must me signed, as dx = x1-x0 may be less than zero as we discussed above. @errordeveloper, please fix and re-enable the 15,15 -> 0,0 test, it should work.

@bharrisau, thanks for catching that.

@bharrisau
Copy link
Contributor

Tests looks great. Thanks for this.

- fix hanging test by fixing signed/unsigned types
- get rid of C copypastaz and not needed mut vars
- more refactoring of while loops
@bharrisau
Copy link
Contributor

We don't get any notifications when you update things - so you need to post here if you are ready for review.

@farcaller
Copy link
Member

Well, I do have notifications for stale "ready for review" PRs, but the script is broken :)

@bharrisau
Copy link
Contributor

A simple r? should be fine. I don't think non-contributors can update
labels on issues.

@farcaller
Copy link
Member

oh well. yes, then a simple 'r?' is fine, somehow I missed the permissions bit.

@errordeveloper
Copy link
Member Author

So is this good to merge now?

@farcaller
Copy link
Member

Yup, thanks for your work.

hacknbot added a commit that referenced this pull request Jul 8, 2014
More int type fixes and tests for drivers

Reviewed-by: farcaller
@hacknbot hacknbot merged commit 3b083b9 into hackndev:master Jul 8, 2014
@errordeveloper errordeveloper deleted the more_int_fixes branch July 8, 2014 16:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants